• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • 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
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

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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