亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

循環由關聯數組組成的數組

循環由關聯數組組成的數組

PHP
慕田峪7331174 2022-01-08 14:58:48
我有一個看起來像這樣的數組:[   {    "positional_index":"1.3",    "sourceid":10409,    "language": "Malayalam",    "field_gita_10409_text": "Behold, O Teacher! this mighty army of the sons of Pandu, arrayed by the son of Drupada, thy wise disciple."   },   {    "positional_index":"1.2",    "sourceid":10409,    "language": "Devanagari",    "field_gita_10409_text": "1.1 Dhritarashtra said What did my people and the sons of Pandu do when they had assembled together eager for battle on the holy plain of Kurukshetra, O Sanjaya."   },]我應該使用 foreach 循環來訪問每個鍵。例如,如果 key = field_gita_10409_text,我必須使用 php 中的 explode() 函數來提取值 10409 等。在這種情況下,我不知道如何使用 foreach 循環,因為該數組包含 2 個關聯數組。請告訴我。
查看完整描述

2 回答

?
汪汪一只貓

TA貢獻1898條經驗 獲得超8個贊

在循環內循環:


foreach ($array as $item){

        foreach ($item as $key=>$value){

            //do stuff

        }

    }


查看完整回答
反對 回復 2022-01-08
?
HUX布斯

TA貢獻1876條經驗 獲得超6個贊

您需要內部循環來獲取鍵和值。


$array = json_decode($json);


foreach ($array as $innerArray){

        foreach ($innerArray as $key=>$value){

            if($key == 'field_gita_10409_text'){

              $exp = explode($value);

            }

        }

    }


查看完整回答
反對 回復 2022-01-08
  • 2 回答
  • 0 關注
  • 131 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號