What is a more elegant solution to these nested if/elseif statements?

后端 未结 9 1889
野趣味
野趣味 2021-01-12 17:09

I\'m building a website that contains users with user profiles. Many of the fields in the profile are optional.

There is an opportunity for a lot of user-generate

9条回答
  •  耶瑟儿~
    2021-01-12 18:09

    //pointers to functions
    $arrayOfSulutions{"display_name_strategy", "full_name_strategy" ..., "null_strategy" } 
    function display_name_strategy{
         return $names['display_name'];
    }
    $i = 0;
    while($res == null){
         $res = call($arrayOfSulutions[$i++]);
    }
    

提交回复
热议问题