我在資料庫中保存了一個 JSON 資料。我想把這些資料放在一個while回圈中,把所有的東西都放在一邊,但我做不到。我該怎么做?
[{"count":33226,"info":"","name":"cash","slot":1,"type":"item"},{"count":1,"info":{"telno":"0662052408","isim":"Bob Brc","aitlik":"steam:1100001179c1b7d","durum":"kilitli"},"name":"phone","slot":2,"type":"item"},{"count":1,"info":{"uniqueId":"3_1","keyData":"z6VAhfL3ppApIXR"},"name":"motel_key","slot":3,"type":"item"},{"count":1,"info":[],"name":"ballasbandana","slot":10,"type":"item"}]
$inventory = $karakter['inventory'];
$inventoryjson = json_decode($inventory, true);
$items = $inventoryjson['name'];
它在我上面的資料庫中的方式,這里有不止一個專案,但我無法將它們分開并將它們放在一個回圈中。底部的代碼欄位也是 PHP 欄位。
uj5u.com熱心網友回復:
你從這個 json 得到的是一個多維陣列,這意味著$items = $inventoryjson['name'];會產生錯誤。
您可以使用 foreach 回圈來獲取正確的資訊,如下所示:
$inventory = $karakter['inventory'];
$items = json_decode($inventory, true);
foreach ( $items as $item ) {
$name = $item['name'];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/426790.html
上一篇:如何讓C 接受ngrok地址?
