<?php
//$arr是一个关联数组,有5个成员
//name,sex,age,education,mobile
$users = [
‘name‘ => [‘张三‘,‘李四‘,‘王五‘,‘赵六‘],
‘sex‘ => [‘男‘,‘女‘,‘女‘,‘男‘],
‘age‘ => [12,13,14,15],
‘education‘ => [‘小学‘,‘本科‘,‘高中‘,‘专科‘],
‘mobile‘ => [1,2,3,4],
];
//转换成
// $arr = [
// 0 => [‘name‘ => 张三, sex =>男, age =>12, edu =>小学, mobile => 1],
// 1 => [‘name‘ => 李四, sex =>女, age =>13, edu =>本科, mobile => 2],
// 2 => [‘name‘ => 王五, sex =>女, age =>14, edu =>高中, mobile => 3],
// 3 => [‘name‘ => 赵六, sex =>男, age =>15, edu =>专科, mobile => 4],
// ]
foreach ($users[‘name‘] as $key => $name) {
// echo $name, $users[‘sex‘][$key], $users[‘age‘][$key],$users[‘education‘][$key],$users[‘mobile‘][$key];
$arr[$key][] = $name;//$arr[0][0] = 张三
$arr[$key][] = $users[‘sex‘][$key];//$arr[1][0] = 男
$arr[$key][] = $users[‘age‘][$key];
$arr[$key][] = $users[‘edcation‘][$key];
$arr[$key][] = $users[‘mobile‘][$key];
}
print_r($arr);