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

PHP Function -> Array

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

$client->getResponse()

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.
0
jaxstorm
Asked:
jaxstorm
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
0
 
Chris HarteThaumaturgeCommented:
So what you are saying is the method getResponse() in the class $client has populated an array.  Use the array name,

$client->getResponse();

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

and it shall work.

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

Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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