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

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

在 PHP 中查找該數(shù)組中的值時(shí),通過鍵刪除關(guān)聯(lián)數(shù)組

在 PHP 中查找該數(shù)組中的值時(shí),通過鍵刪除關(guān)聯(lián)數(shù)組

PHP
拉風(fēng)的咖菲貓 2021-12-03 14:56:59
我有一個(gè)現(xiàn)有的多個(gè)數(shù)組的關(guān)聯(lián)數(shù)組。然后我有一個(gè)“名稱”數(shù)組,我需要在前一個(gè)數(shù)組中找到每個(gè)“名稱”,并通過鍵刪除該數(shù)組。這里的目標(biāo)是獲取現(xiàn)有的文檔數(shù)組,允許用戶“刪除”它們,所以我必須比較用戶想要?jiǎng)h除的文件的名稱,然后在我的父數(shù)組中取消設(shè)置這些數(shù)組中的每一個(gè),然后通過將這個(gè)最終數(shù)組存入數(shù)據(jù)庫(kù)以保存為用戶的“更新”列表。偽代碼將是: - 比較$names每個(gè)名稱的數(shù)組,查找與數(shù)組中的名稱匹配的$parentArray鍵。在 this 中,未設(shè)置的數(shù)組。name$namesforeach我的多個(gè)數(shù)組的關(guān)聯(lián)數(shù)組在這里:Array([0] => PetManagement\\Pet\\Document Object([file:protected] => https://url.com/file_example_MP3_700KB.mp3[name:protected] => file_example_MP3_700KB.mp3[fileType:protected] => audio/mp3[timestamp:protected] => 2019-08-21 08:28:12[authorID:protected] => 2[extension:protected] =>[extensionIcon:protected] =>)[1] => PetManagement\\Pet\\Document Object([file:protected] => https://url.com/file-sample_100kB.docx[name:protected] => file-sample_100kB.docx[fileType:protected] => application/vnd.openxmlformats-officedocument.wordprocessingml.document[timestamp:protected] => 2019-08-21 08:28:12[authorID:protected] => 2[extension:protected] =>[extensionIcon:protected] =>)[2] => PetManagement\\Pet\\Document Object([file:protected] => https://url.com/file-sample_100kB.odt[name:protected] => file-sample_34343kB.odt[fileType:protected] => application/vnd.oasis.opendocument.text[timestamp:protected] => 2019-08-21 08:28:12[authorID:protected] => 2[extension:protected] =>[extensionIcon:protected] =>))我傳入了一個(gè)“名稱”數(shù)組,例如['file-sample_100kB.odt','file_example_MP3_700KB.mp3'],我想搜索這個(gè)大數(shù)組以刪除name鍵與該數(shù)組中的每個(gè)值相匹配的鍵,以及unset鍵。因此,在我的示例中,使用$names數(shù)組,我將刪除 key3和 0.我一直在使用的通用代碼如下,但我似乎無(wú)法讓它正常工作:$docs = $p->getDocuments(); //existing $parentArray$docsToRemove = explode(',',$this->postData['documents']); //create array of names we want to remove from $docsforeach ($docsToRemove as $key=>$value) {    //$value is the name we want to remove    //'name' is the assoc array key we want to remove    error_log(print_r(array_search($value, array_column($docs, 'name'))),true); //returns empty array}任何幫助將不勝感激。在此之前,我是做多foreach環(huán),但使用的混合被告知只是array_search()和array_column()會(huì)是一個(gè)更好更先進(jìn)的解決方案。
查看完整描述

1 回答

?
瀟湘沐

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

用這樣的回調(diào)過濾你的數(shù)組:


$docsToRemove = explode(',',$this->postData['documents']); //create array of names we want to remove from $docs


$filtered = array_filter(

    $docs,

    function ($doc) use ($docsToRemove) { return !in_array($doc->getName(), $docsToRemove); }

);


查看完整回答
反對(duì) 回復(fù) 2021-12-03
  • 1 回答
  • 0 關(guān)注
  • 166 瀏覽

添加回答

舉報(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)