I now have more than 1000 data in the two-dimensional array, the fields in each data are redundant, I now only need my red box in each of the 3 target fields will be OK, the others do not,
I now know to use a double foreach loop to do, but always do not come out, but also ask you to help answer, thank you
The figure is as follows:
Reply content:
I now have more than 1000 data in the two-dimensional array, the fields in each data are redundant, I now only need my red box in each of the 3 target fields will be OK, the others do not,
I now know to use a double foreach loop to do, but always do not come out, but also ask you to help answer, thank you
The figure is as follows:
Do you want to take out the field you want in the two-bit array, not two times? foreach
mt_rand(1, 2000), 'good_name' => 'goodname' . $i, 'xxxxxxx' => 'xxxxx', 'wadadad' => 'adwawdadwad', 'remake' => '' ];}//---构造测试数据 ---$data = [];foreach ($arry as $key => $value) { $data[] = [ 'platform_good_id' => $value['platform_good_id'], 'good_name' => $value['good_name'], 'remake' => $value['remake'], ];}var_dump($data);
As follows:
array("a"=>"a","b"=>"b","c"=>"c","d"=>"d","e"=>"e"), "b"=>array("a"=>"a","b"=>"b","c"=>"c","d"=>"d","e"=>"e"), "c"=>array("a"=>"a","b"=>"b","c"=>"c","d"=>"d","e"=>"e"), "d"=>array("a"=>"a","b"=>"b","c"=>"c","d"=>"d","e"=>"e"), "e"=>array("a"=>"a","b"=>"b","c"=>"c","d"=>"d","e"=>"e"));$result = array();foreach ($arr as $k => $v){ $result[$k] = array(); foreach($v as $key => $value){ if($key === "b" || $key === "d" || $key === "e"){ $result[$k][$key] = $value; } }}print_r($arr);print("
");print_r($result);?>
The code above is to extract the element where the key value is b d e
and then compose a new array.