<?php
//$a为车子的名称
//$b为车子的型号
//需要实现把车子的型号放到车子名字下,关联字段$b中的pid对应$a中的id
$a = [
['id' => 1, 'name' => '奥迪'],
['id' => 2, 'name' => '奔驰'],
['id' => 3, 'name' => '玛莎拉蒂']
];
$b = [
['id' => 1, 'name' => 'A4', 'pid' => 1],
['id' => 2, 'name' => 'A6', 'pid' => 1],
['id' => 3, 'name' => 'S600', 'pid' => 2]
];
foreach ($a as $k => $v) {
$info = [];
foreach ($b as $kk => $vv) {
if ($vv['pid'] == $v['id']) {
$info[] = $vv;
}
}
$a[$k]['extra'] = $info;
}
echo "<pre>";
var_dump($a);
?>
php中关系数组处理
最新推荐文章于 2022-10-20 16:44:46 发布