laravel 将文件内容传输到集合

ff29svar  于 2022-11-18  发布在  其他
关注(0)|答案(1)|浏览(85)

如何将文件的内容传输到集合
文件内容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],  
]
j1dl9f46

j1dl9f461#

假设文件格式正确,我将使用json_decode()函数。

$contents = json_decode(Storage::get('test.txt'), true);

如果你想要一个laravel系列

$collection = collect($contents);

相关问题