【发布时间】:2016-05-27 10:44:57
【问题描述】:
我有大约 850 个 json 文件,我想将它们合并为 50 个一组。 最好的方法是什么?
array_merge ?
我见过一些例子,但没有一个超过 2 个数组。
<?
$array1 = json_decode(file_get_contents('1.json'));
$array2 = json_decode(file_get_contents('2.json'));
$array3 = json_decode(file_get_contents('3.json'));
$array4 = json_decode(file_get_contents('4.json'));
$array5 = json_decode(file_get_contents('5.json'));
$array6 = json_decode(file_get_contents('6.json'));
$array7 = json_decode(file_get_contents('7.json'));
$array8 = json_decode(file_get_contents('8.json'));
$array9 = json_decode(file_get_contents('9.json'));
$array10 = json_decode(file_get_contents('10.json'));
$array11 = json_decode(file_get_contents('11.json'));
$array12 = json_decode(file_get_contents('12.json'));
$array13 = json_decode(file_get_contents('13.json'));
$array14 = json_decode(file_get_contents('14.json'));
$array15 = json_decode(file_get_contents('15.json'));
$result = array_merge($array14, $array15);
var_dump(json_encode($result));
?>
JSON 1 的示例:http://pastebin.com/QDyGGjQj
有希望的结果(50 分中的 3 分,因为 50 是一个很好的例子): http://pastebin.com/fP2MHN2Y
【问题讨论】:
-
你可以在
array_merge函数中给n个数组作为参数