PHP多个一维数组合并成二维数组的简易方法

当我们需要进行数组遍历数据的时候,需要将多个一维数组进行二维的转换,方法很简单。如下:

<?php  
  $a= array('张三','李四','王五');  
  $b= array ('23','24','25');  
  $c= array ('北京','上海','广州' );  
  foreach($a as $key=>$val){      $d[$key]['姓名']=$a[$key];  
    $d[$key]['年龄']=$b[$key];  
    $d[$key]['城市']=$c[$key];  
  }  
  
  echo "pre";
   var_dump($d);  
?>

转载 :https://www.cnblogs.com/wenzheshen/p/7120028.html

 

---------------------------------------------------------------自己项目---------------------------------------------------------------------

 

        $param = $this->request->param('');

$total_amount_arr = $param['total_amount'];
$student_order_list_id_arr = $param['student_order_list_id'];



$StudentOrderListModel = new \app\admin\model\StudentOrderList();

dump($total_amount_arr);
dump($student_order_list_id_arr);
foreach($student_order_list_id_arr as $key => $val){
$d[$val]=$total_amount_arr[$key];

}
dump($d);die;

 

array(3) {
  [0] => string(2) "24"
  [1] => string(3) "543"
  [2] => string(4) "7657"
}
array(3) {
  [0] => string(1) "1"
  [1] => string(1) "2"
  [2] => string(1) "3"
}

组成的新数组
array(3) {
  [1] => string(2) "24"
  [2] => string(3) "543"
  [3] => string(4) "7657"
}

 

 

 
 
posted @ 2021-02-07 17:22  搬砖小伙子  阅读(850)  评论(0编辑  收藏  举报