第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

根據(jù)模式排列 PHP 數(shù)組

根據(jù)模式排列 PHP 數(shù)組

PHP
ITMISS 2022-01-02 13:54:06
鑒于閑置的 $array:Array ([0] => Array    (        [location_id_keep] => 25        [location_id_delete] => 1    )[1] => Array    (        [location_id_keep] => 26        [location_id_delete] => Array            (                [0] => 3                [1] => 4            )    ))我想將像休閑模式這樣的元素分組到結(jié)果:Array ([0] => Array    (        [location_id_keep] => 25        [location_id_delete] => 1    )[1] => Array    (        [location_id_keep] => 26        [location_id_delete] => 3    )[2] => Array    (        [location_id_keep] => 26        [location_id_delete] => 4    ))規(guī)則應(yīng)該是這樣的,對(duì)于輸入數(shù)組中的每個(gè)數(shù)組,將 [location_id_keep] 與每個(gè) [location_id_delete] 分組,從而為每個(gè) [location_id_delete] 生成一個(gè)新數(shù)組,就像在所需的輸出示例中一樣。到目前為止我嘗試過(guò)的:foreach ($array as $id) {//check if location_id_delete have more than 1 value                if( $id["location_id_delete"][1]) {                    foreach($id["location_id_delete"] as $del){                         $array["location_id_delete"][] = $del;                    $array["location_id_keep"]=id["location_id_keep"];                    }                }            }
查看完整描述

1 回答

?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

$output = array();

foreach ($array as $i => $id) {

//check if location_id_delete have more than 1 value

  if( is_array($id["location_id_delete"])) {

    foreach($id["location_id_delete"] as $del){

      $output[] = array(

        'location_id_keep' => $array[$i]["location_id_keep"],

        'location_id_delete' => $del

      );

    }

  }else{

    $output[] = $array[$i];

  }

}

var_dump($output);


查看完整回答
反對(duì) 回復(fù) 2022-01-02
  • 1 回答
  • 0 關(guān)注
  • 141 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)