Multiple returns from a function

后端 未结 30 2770
盖世英雄少女心
盖世英雄少女心 2020-11-22 06:12

Is it possible to have a function with two returns like this:

function test($testvar)
{
  // Do something

  return $var1;
  return $var2;
}
<
30条回答
  •  甜味超标
    2020-11-22 06:44

    You can return multiple arrays and scalars from a function

    function x()
    {
        $a=array("a","b","c");
        $b=array("e","f");
        return array('x',$a,$b);
    }
    
    list ($m,$n,$o)=x();
    
    echo $m."\n";
    print_r($n);
    print_r($o);
    

提交回复
热议问题