更新时间:2023-12-04 14:11:04
另一种替代方法是使用 halaxa/json -机器.
Another alternative is to use halaxa/json-machine.
通过JSON进行迭代的用法与json_decode
的用法相同,但是无论文件有多大,它都不会达到内存限制.无需执行任何操作,只需执行foreach
.
Usage in case of iteration over JSON is the same as in case of json_decode
, but it will not hit memory limit no matter how big your file is. No need to implement anything, just your foreach
.
示例:
$users = \JsonMachine\JsonMachine::fromFile('500MB-users.json');
foreach ($users as $id => $user) {
// process $user as usual
}
有关更多详细信息,请参见github自述文件.
See github readme for more details.