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

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

在 PHP 中從 JSON 數(shù)組中獲取隨機(jī)項(xiàng)

在 PHP 中從 JSON 數(shù)組中獲取隨機(jī)項(xiàng)

PHP
慕森卡 2023-08-19 16:59:13
我無法使用以下 JSON 獲取隨機(jī)項(xiàng)目$str = file_get_contents("wisdomquotes.txt"); $array = json_decode($str, true); //Fine up to here$rand = $array[array_rand($array)];//Returns entire array instead of a single random item這是 JSON:{    "quotes": [{        "keywords": ["work"],        "quote": " A stich in time saves nine"    }, {        "keywords": ["health"],        "quote": " An apple a day keeps the doctor away."    }, {        "keywords": ["money"],        "quote": " A penny save is a penny earned."    }, {        "keywords": ["work"],        "quote": " You can't burn the candle at both ends."    }, {        "keywords": [""],        "quote": "Tis better to light a candle than to curse the darkness"    }]}獲得隨機(jī)物品的正確代碼是什么?
查看完整描述

3 回答

?
神不在的星期二

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

這是因?yàn)槟那闆r下的主數(shù)組位于quotes子數(shù)組內(nèi)。

$rand = $array['quotes'][\array_rand($array['quotes'])];


查看完整回答
反對(duì) 回復(fù) 2023-08-19
?
慕妹3146593

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

你可以試試這個(gè):


$str = file_get_contents("wisdomquotes.txt"); 

$array = json_decode($str, true);

$rand = array_rand($array['quotes'], 1);

var_dump($array['quotes'][$rand]);


查看完整回答
反對(duì) 回復(fù) 2023-08-19
?
LEATH

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

您可能會(huì)瞄準(zhǔn)$array['quotes']

array_rand($array['quotes'], 1);


查看完整回答
反對(duì) 回復(fù) 2023-08-19
  • 3 回答
  • 0 關(guān)注
  • 197 瀏覽

添加回答

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