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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當(dāng)多次使用相同的鍵時,如何回顯特定的數(shù)組鍵?

當(dāng)多次使用相同的鍵時,如何回顯特定的數(shù)組鍵?

PHP
胡子哥哥 2021-11-13 17:28:07
我有一個數(shù)組,我正在嘗試使用 PHP 進行迭代并從中獲取一個值。我所有的“custom_attributes”鍵都是一樣的。Array(    [items] => Array        (            [0] => Array                (                    [sku] => SCB20                    [custom_attributes] => Array                        (                            [0] => Array                                (                                    [attribute_code] => ages                                    [value] => 17                                )                            [1] => Array                                (                                    [attribute_code] => description                                    [value] => description data                                )                            [2] => Array                                (                                    [attribute_code] => image                                    [value] => cl2eojpu9.jpg                                )                        )                )        ))例如,假設(shè)我只想回顯 value 的值,其中 attribute_code 值等于年齡。我怎么做?
查看完整描述

2 回答

?
牛魔王的故事

TA貢獻1830條經(jīng)驗 獲得超3個贊

您可以像下面這樣循環(huán)數(shù)組:


    foreach ($array['items'][0]['custom_attributes'] as $key => $item) {

      if($item['attribute_code'] == 'ages') echo $item['value']

    }


查看完整回答
反對 回復(fù) 2021-11-13
?
元芳怎么了

TA貢獻1798條經(jīng)驗 獲得超7個贊

您可以使用 array_walk_recursive


 $searchCode  = 'ages';

 $attributeValue = '';

 $flag = false;

 array_walk_recursive($a, function($item, $key, &$flag) use ($searchCode,&$attributeValue){

  ($key == 'attribute_code' && $item == $searchCode) ? ($flag = true) : '';

  !empty($flag) ? ($attributeValue = $item) : '';

 }, $flag);

 echo $attributeValue;

工作示例:https : //3v4l.org/erlZD


查看完整回答
反對 回復(fù) 2021-11-13
  • 2 回答
  • 0 關(guān)注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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