Answer the question
In order to leave comments, you need to log in
Can a function return 2 values?
$a = 2; $b = 3;
function Num($a, $b){
$c = $a + $b;
$d = $a * $b;
return $c, $d; // Вот тут весь вопрос
}
Answer the question
In order to leave comments, you need to log in
You can return an array
$a = 2; $b = 3;
function Num($a, $b){
$c = $a + $b;
$d = $a * $b;
return [$c, $d];
}
list($c, $d) = Num($a, $b);
echo "$c|$d";
// 5|6
$a = 2; $b = 3; $c = $d = null;
function Num($a, $b, &$c, &$d){
$c = $a + $b;
$d = $a * $b;
}
Num($a, $b, &$c, &$d);
echo "$c|$d";
// 5|6
return $c;
return $d;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question