Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP Function -> Array

Posted on 2011-03-07
5
Medium Priority
?
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 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 17

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 143

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 143

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 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