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.
$a = get_array(); $a[0]; Php is not javascript for you. =)
P.S. And in javascript, get_array()[0]; .
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']); Source: https://ru.stackoverflow.com/questions/57745/
All Articles