In php how can I access an array’s values without using square brackets around the key? My particular problem is that I want to access the elements of an array returned by a function. Say function(args) returns an array. Why is
$var = function(args)[0];
yelling at me about the square brackets? Can I do something like
$var = function(args).value(0);
or am I missing something very basic?
In php how can I access an array’s values without using square brackets around
Share
As the others have said, you pretty much have to use a temporary variable:
But, if know the structure of the array being returned it is possible to avoid the temporary variable.
If you just want the first member:
If you want the last member:
If you want any one in between: