• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

PHP Function -> Array

I have a PHP function which populates a multi-dimensional array


I want to utilise that array directly, something like this:

echo '$client->getResponse()[0]'; which obviously doesn't work.

I don't want to have to do this

$arr = array($client->getResponse()); as that brings in another level of array which I don't really want.
1 Solution
Beverley PortlockCommented:
You cannot echo an array use print_r instead http://www.php.net/print_r

If your function returns an array then

$arr = $client->getResponse();

should be sufficient to store it in $arr - no extra array levels needed
Chris HarteThaumaturgeCommented:
So what you are saying is the method getResponse() in the class $client has populated an array.  Use the array name,


echo $array_name[0];
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you remove the quotes:
echo $client->getResponse()[0];

and it shall work.

$arr = $client->getResponse();
echo $arr[0];
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry for the "last" post, EE seems to have some upgrade/downtime issues in the last hours ...
jaxstormAuthor Commented:
Aye that's got it, having a slow day.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now