help with passing arguments to function

前端 未结 6 1116
慢半拍i
慢半拍i 2020-12-06 23:49
function get_tags_by_criteria($gender=\"%\", $min_age_of_birth=\"%\", $max_age_of_birth=\"%\", $country=\"%\", $region=\"%\", $city=\"%\", $tag=\"\") {
6条回答
  •  心在旅途
    2020-12-07 00:53

    There is no named parameter passing in PHP. Generally if you have more than about 4 parameters and lots of them are optional you might want to consider using an array or object instead:

    function get_tags_by_criteria($args) {
      ...
    }
    
    get_tags_by_criteria(array('gender' => 'M', 'tag' => 'php'));
    

    You can explicitly set the parameters allowed by using an object instead.

提交回复
热议问题