php - I have this kind of an array. and want result like below arrays -


i have following array

$result=array( [name] => array( [0] => xyz1 [1] => xyz2 ) [email] => array ( [0] => xyz1@gmail.com [1] => xyz2@gmail.com ) [phone] => array ( [0] => 23423423-1 [1] => 23423423-2 ) [address] => array ( [0] => xyz1 [1] => xyz2 ));     

and want

$r1=array ( [name] => xyz1 [email] => xyz1@gmail.com [phone] => 23423423-1 [address] => xyz1 );   $r2=array ( [name] => xyz2 [email] => xyz2@gmail.com [phone] => 23423423-2 [address] => xyz2 ); 

assuming keys correspond each other indexes, i.e. 1st email value corresponds 1st name value etc, can loop through indexes , keys generate new array:

foreach(array_keys($result['name']) $i) {      $row = array();      foreach(array_keys($result) $key) {         $row[$key] = $result[$key][$i];     }      print_r($row); } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -