php中关系数组处理

 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 "
";
var_dump($a);
?>

你可能感兴趣的:(PHP)