How to pass an array into a function, and return the results with an array

后端 未结 9 1405
你的背包
你的背包 2021-02-05 07:25

So I\'m trying to learn how to pass arrays through a function, so that I can get around PHP\'s inability to return multiple values. Haven\'t been able to get anything to work so

9条回答
  •  走了就别回头了
    2021-02-05 08:08

    You are not able to return 'multiple values' in PHP. You can return a single value, which might be an array.

    function foo($test1, $test2, $test3)
    {
        return array($test1, $test2, $test3);
    }
    $test1 = "1";
    $test2 = "2";
    $test3 = "3";
    
    $arr = foo($test1, $test2, $test3);
    
    $test1 = $arr[0];
    $test2 = $arr[1];
    $test3 = $arr[2];
    

提交回复
热议问题