这是一个测试的三维数组:
$arr = [ [ [ 'name' => 'zhangsan', 'age' => 16 ], [ 'name' => 'lisi', 'age' => 17 ], [ 'name' => 'wangwu', 'age' => 15 ], ],[ [ 'name' => 'zhangsan', 'age' => 16 ], [ 'name' => 'lisi', 'age' => 13 ], [ 'name' => 'wangwu', 'age' => 15 ], ] ];
循环获取值:
$age = []; foreach($arr as $value){ foreach($value as $v){ if (in_array($v['age'], $age)) { continue; } $age[] = $v['age']; $arr2[]=$v; } } var_dump($arr2);exit;
打印的结果: