search

Home  >  Q&A  >  body text

php array conversion

$da = array(
            'name'=>array('0'=>'张三','1'=>'李四','2'=>'王五'),
            'pwd'=>array('0'=>'zs1234','1'=>'wa1234','2'=>'ww1234'),
            'tel'=>array('0'=>'13255557785','1'=>'15624845761','2'=>'18547842158')
        );
        
$de = array(
            '0'=>array('name'=>'张三','pwd'=>'zs1234','tel'=>'13255557785'),
            '1'=>array('name'=>'李四','pwd'=>'wa1234','tel'=>'15624845761',),
            '2'=>array('name'=>'王五','pwd'=>'ww1234','tel'=>'18547842158',)
        );

Could you please tell me how to convert array $da into array $de

笑呵呵笑呵呵2381 days ago953

reply all(2)I'll reply

  • 笑呵呵

    笑呵呵2018-06-28 17:36:55

    Thanks, I found another way $de=array(); foreach($da as $key=>$value){ for($i=0;$i<=count($da[$key]) -1;$i++){ foreach(array_keys($da) as $dek=>$dev){ $de[$i][$dev]=$da[$dev][$i]; } } } print_r ($de);

    reply
    0
  • 威尼斯

    威尼斯2018-06-28 17:22:05

    $da = array( 'name'=>array('0'=>'张三','1'=>'李四','2'=>'王五'), 'pwd'=>array('0'=>'zs1234','1'=>'wa1234','2'=>'ww1234'), 'tel'=>array('0'=>'13255557785','1'=>'15624845761','2'=>'18547842158'));$de=array();for($i=0;$i<count($da['name']);$i++){ $de[$i]['name']=$da['name'][$i]; $de[$i]['pwd']=$da['pwd'][$i]; $de[$i]['tel']=$da['tel'][$i];}var_dump($de);exit;

    reply
    0
  • Cancelreply