How to access the elements of a function's return array?

后端 未结 15 2266
栀梦
栀梦 2020-12-05 03:46

I need to return multiple values from a function, therefore I have added them to an array and returned the array.



        
15条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 04:22

    You can add array keys to your return values and then use these keys to print the array values, as shown here:

    function data() {
        $out['a'] = "abc";
        $out['b'] = "def";
        $out['c'] = "ghi";
        return $out;
    }
    
    $data = data();
    echo $data['a'];
    echo $data['b'];
    echo $data['c'];
    

提交回复
热议问题