Создание функции PHP с несколькими возвратами Массив PHP для возврата нескольких значений <?php funtion arrayFunc(){ $var1 = "return 1"; $var2 = "return 2"; return array($var1, $var2); } $result = arrayFunc(); var_dump($result); //output: array(2) { [0]=> string(8) "return 1" [1]=> string(8) "return 2" } $result = arrayFunc(); echo $result[0]; // return 1 echo $result[1]; // return 2 $array = ['dog', 'cat', 'horse', 'fish']; [$q, $w, $e, $r] = $array; echo $q; // output: dog echo $w; // output: cat function descructingFunction(){ return ['A', 'sample', 'descructing', 'function']; } [$a, $b, $c, $d] = descructingFunction(); echo $a; //output: A echo $d; // output: function ?>PHPCopy Функция PHP с условным внутренним возвратом <?php function condFunc($x = true){ $ret1 = "One"; $ret2 = "Two"; if($x == true){ return $ret1; }else{ return $ret2; } } echo condFunc(true); //output: One ?>PHPCopy Комбинация массива PHP и динамического возврата <?php function combination($x = true){ $ret1 = "One"; $ret2 = "Two"; if($x === true){ return $ret2; } if($x == "both"){ return array($ret1, $ret2); } } echo combination(); //output: Two var_dump(combination("both")) //output: array(2) { [0]=> string(8) "return 1" [1]=> string(8) "return 2" } ?>PHPCopy PHP generatorдля нескольких значений yield <?php function multipleValues(){ yield "return 1"; yield "return 2"; } $return = multipleValues(); foreach($return as $ret){ echo $ret; //$ret first value is "return 1" then "return 2" } $generator = (yield $test); ?>PHPCopy PHP PHP