arrayToArray
Posted lujieting
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arrayToArray相关的知识,希望对你有一定的参考价值。
<?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);
以上是关于arrayToArray的主要内容,如果未能解决你的问题,请参考以下文章