0

can someone help me to echo [city] value and [country] value from following array:

<?php Array ( [0] => Array ( [uid] => 123456789 [name] => First Last Name [current_location] => Array ( [city] => New York [state] => New York [country] => United States [zip] => [id] => 123456789 [name] => New York, New York ) [profile_url] => http://www.facebook.com/username ) ) ?> 

thanks.

1
  • 4
    echo yourArray[0]['current_location']['city'], yourArray[0]['current_location']['country']; Commented Oct 4, 2011 at 19:37

3 Answers 3

4

You have a multidimensional array. You want to try this:

echo $arr[0]['current_location']['city']; echo $arr[0]['current_location']['country']; 
Sign up to request clarification or add additional context in comments.

Comments

1

Like this:

echo $somearray[0]['current_location']['city']; echo $somearray[0]['current_location']['country']; 

Comments

0

As has already been pointed out, you have a multidimensional array - in other words an array inside an array.

This kind of data is usually accessed like this:

foreach ($yourArray as $data) { $locationData = $data['current_location']; echo "user id " . $data['uid'] . "\n"; echo " - city " . $locationData['city'] . "\n"; echo " - country " . $locationData['country'] . "\n"; } 

So if more than one user appears in the data, you can handle each one.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.