php - check is array multidimensional -


i have array, form like:

//1st form     $a = array(     'req' => array(         'name' => 'lia',         'email' => 'lia@maya.com'     ) );  , sometime like: //2nd form      $a = array(     'req' => array(         array(             'name' => 'lia',             'email' => 'lia@maya.com'         ),         array(             'name' => 'citra',             'email' => 'citra@maya.com'         )     ) ); 

its confused when decide use loop. want, if array 1st form looping process

foreach ($advrs['req'] $key => $row) {         $emails[] = $row['email'];     } 

and when array in second form use looping process.

 foreach ($advrs['req'] $key => $row) {         foreach ($row $list) {             $emails[] = $list['email'];         }     } 

how make it? thank you.

try is_array like

foreach ($advrs['req'] $key => $row) {     if(is_array($row)) {         foreach ($row $list) {             $emails[] = $list['email'];         }     } else {         $emails[] = $row['email'];     }  } 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -