我有一个包含14个元素的JSON。我怎样才能把它分成更小的 JSON,每个 JSON 比如说 2 或 3 个元素。
不知道你的确切 json 是什么,但这将作为一个示例:
<?php
$jsonExample = '["a","b","c","d","e","f","g","h","i"]' ;
$arrResult = json_decode($jsonExample,true);
$output = array_chunk($arrResult,3);
var_dump($output);
?>
demo:http://codepad.org/aYBg19DB
我建议使用json_decode()和array_chunk()。
http://php.net/manual/en/function.array-chunk.php
http://php.net/manual/en/function.json-decode.php