Question

I have a JSON containing lets say 14 elements. How can I divide it in smaller JSONs of lets say 2 or 3 elements each.

Was it helpful?

Solution

Do not know what your exact json is, but this will serve as an example:

<?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

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top