如何將檔案的內容傳輸到集合
檔案內容test.txt
[
{"nmId":40699165,"price":924,"discount":0,"promoCode":0},
{"nmId":40384610,"price":4155,"discount":0,"promoCode":0}
]
我是這樣理解的
$contents = Storage::get('test.txt');
我想在輸出中看到一個集合
[
['nmId' => '40699165', 'price' => 924, 'discount' => 0, 'promoCode' => 0],
['nmId' => '40384610', 'price' => 4155, 'discount' => 0, 'promoCode' => 0],
]
uj5u.com熱心網友回復:
假設檔案格式正確,我會使用 json_decode() 函式。
$contents = json_decode(Storage::get('test.txt'), true);
如果你想要一個 laravel 集合
$collection = collect($contents);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/535883.html
標籤:PHP拉维
