Reputation: 1169
When function return an array and we just need for particular key value can we use it like this:-
$obj->functionName($para)["x"];
is this proper way of doing this or should use variable?
Upvotes: 0
Views: 685
Reputation: 2748
Yes it works fine, you don't have to make variable and waste memory.
<?php
function getArray() {
return [ 'name1', 'name2', 'name3'];
}
echo getArray()[1];
?>
Upvotes: 2