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]
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.
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.
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.
Look at the keys and indentation in your print_r
:
echo $myarray[0]['email']; echo $myarray[0]['gender'];
...etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With