There is a function that returns an array. How can I refer to its elements? For example:

function get_array(){ ... return $arr; } 

If you try echo get_array()[0]; , PHP will generate an error.

    2 answers 2

     $a = get_array(); $a[0]; 

    Php is not javascript for you. =)

    P.S. And in javascript, get_array()[0]; .

    • Tau I already did :-). Directly means you can not turn? - alex_90
    • Alas, no way. - ling

    And if you use such a crutch :)))

     class A{ public $data=array(); function __construct($data){ $this->data=$data; } } function returnArray($data){ $a=new A($data); return $a; } print_r(returnArray(array('msg'=>'Hello World'))->data['msg']);