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

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

從PHP中的嵌套數(shù)組中刪除元素

從PHP中的嵌套數(shù)組中刪除元素

PHP
富國滬深 2021-05-04 15:46:07
我在Laravel應(yīng)用程序上工作,因此我有一個(gè)關(guān)聯(lián)數(shù)組要傳遞給API端點(diǎn)。在發(fā)布到API之前,我想刪除img鍵及其值。我嘗試使用未設(shè)置的功能,但未刪除img鍵我要?jiǎng)h除圖像屬性的數(shù)組 $a[] = [  0 => array:4 [    "name" => "Martoo nnn"    "relationship" => "Spouse"    "dob" => "2001-02-03"    "img" => "img.png"  ]  1 => array:4 [    "name" => "sdsdsd sdsdsd"    "relationship" => "Child"    "dob" => "2019-04-04"    "img" => "img1.png"  ]  2 => array:4 [    "name" => "sdsdsd sddds"    "relationship" => "Child"    "dob" => "2019-04-05"    "img" => "img2.png"  ]  3 => array:4 [    "name" => "dssdsd dsdsd"    "relationship" => "Child"    "dob" => "2019-04-02"    "img" => "img3.png"  ]  4 => array:4 [    "name" => "dssdsd dssdsd"    "relationship" => "Child"    "dob" => "2019-04-04"    "img" => "img4.png"  ]];取消設(shè)定方法$array = $a;unset($array['img']);//dd($a);
查看完整描述

2 回答

?
寶慕林4294392

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

你可以做這樣的事情,


foreach ($array as $key => &$value) { // & defines changes will be made @ value itself

    unset($value['img']);

}

是的,我不明白您為什么要初始化$a為$a[]?


查看完整回答
反對(duì) 回復(fù) 2021-05-14
?
人到中年有點(diǎn)甜

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

$newarray = array_filter($a, function($k) {

    return $k != 'img';

}, ARRAY_FILTER_USE_KEY);

并傳遞這個(gè)新數(shù)組


查看完整回答
反對(duì) 回復(fù) 2021-05-14
  • 2 回答
  • 0 關(guān)注
  • 194 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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