Solved

PHP Function -> Array

Posted on 2011-03-07
5
249 Views
Last Modified: 2012-05-11
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
Comment
Question by:jaxstorm
5 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 35056002
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
 
LVL 16

Expert Comment

by:Chris Harte
ID: 35056085
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35056109
you remove the quotes:
echo $client->getResponse()[0];

and it shall work.

or:
$arr = $client->getResponse();
echo $arr[0];
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35056121
sorry for the "last" post, EE seems to have some upgrade/downtime issues in the last hours ...
0
 
LVL 8

Author Closing Comment

by:jaxstorm
ID: 35056320
Aye that's got it, having a slow day.

Thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now