Two-dimensional arrays select only target fields

Source: Internet
Author: User

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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.