?
Solved

PHP Function -> Array

Posted on 2011-03-07
5
Medium Priority
?
293 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 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