Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get single value from this multi-dimensional PHP array

Tags:

arrays

php

Example print_r($myarray)

Array (     [0] => Array     (         [id] => 6578765         [name] => John Smith         [first_name] => John         [last_name] => Smith         [link] => http://www.example.com         [gender] => male         [email] => [email protected]         [timezone] => 8         [updated_time] => 2010-12-07T21:02:21+0000     ) ) 

Question, how to get the $myarray in single value like:

echo $myarray['email'];  will show [email protected] 
like image 609
wow Avatar asked Dec 08 '10 03:12

wow


People also ask

How do you find a single value from an array?

In an indexed array, all the array elements are represented by the index, which is a numeric value starting from 0 (zero). We can get the single array value from the indexed array either using array index or key.

How do you find the value of multidimensional array?

Size of multidimensional arrays: The total number of elements that can be stored in a multidimensional array can be calculated by multiplying the size of all the dimensions. For example: The array int[][] x = new int[10][20] can store a total of (10*20) = 200 elements.

How do you loop through a multidimensional array in PHP?

Looping through multidimensional arrays Just as with regular, single-dimensional arrays, you can use foreach to loop through multidimensional arrays. To do this, you need to create nested foreach loops — that is, one loop inside another: The outer loop reads each element in the top-level array.


1 Answers

Look at the keys and indentation in your print_r:

echo $myarray[0]['email'];  echo $myarray[0]['gender']; 

...etc

like image 86
Dan Grossman Avatar answered Nov 15 '22 13:11

Dan Grossman