php - Get items in multidimensional array separately -


i have array ($myarray) this:

print_r(array_values ($myarray));  result: array (      [0] =>      [1] => array (          [id] => 1          [name] => abc      )      [2] => array (          [id] => 2          [name] => def      )  ) 

i'm trying each id , name.. im trying this:

foreach ($myarray $value) {     foreach($value $result) {         echo $result;     } } 

i'm facing 2 problems:

  1. i php warning says: " invalid argument supplied foreach() on line 29

this line is: foreach($value $result) {

  1. i keys id , name place them in correct places. ways echo "1abc" , "2def"

any idea? helping.

basically, error triggered, since array in example (index 0 in particular) not array (most empty string/null ) being used inside foreach.

since 1 of elements not array, check if array or not using is_array():

foreach($myarray $values) {     if(is_array($values)) {         echo $values['id'] . ' ' . $values['name'] . '<br/>';     } } 

alternatively, use array_filter() in case in turn removes empty index zero, use loop have. wouldn't have check empty element.

$myarray = array_filter($myarray); foreach ($myarray $value) {     foreach($value $result) {         echo $result;     } } 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -