Solved

PHP Function -> Array

Posted on 2011-03-07
5
259 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

20 Experts available now in Live!

Get 1:1 Help Now