Код: Выделить всё
array(5) {
[0]=> array(1)
[0]=> int(1)
[1]=> array(1)
[0]=> int(2)
[2]=> array(1)
[0]=> int(3)
[3]=> array(1)
[0]=> int(4)
[4]=> array(1)
[0]=> int(5)
}
(Фактически разделить массив на его длину)
Это мой код:
Код: Выделить всё
$temp = array();
function toArr(){
return func_get_args();
}
//{('a',1),('b',2),('c',3),('d',4),('e',5)}
$a = array ('a','b','c','d','e');
$b = array(1,2,3,4,5);
$c = array_map ('toArr',$a,$b);
$collection1 = array_slice($c, 0, 1, true);
$collection2 = array_slice($c, 1, 1, true);
$collection3 = array_slice($c, 2, 1, true);
$collection4 = array_slice($c, 3, 1, true);
$collection5 = array_slice($c, 4, 1, true);
$temp[] = $collection1;
$temp[] = $collection2;
$temp[] = $collection3;
$temp[] = $collection4;
$temp[] = $collection5;
$jsondata = json_encode($temp);
echo $jsondata;
Код: Выделить всё
[[["a",1]],{"1":["b",2]},{"2":["c",3]},{"3":["d",4]},{"4":["e",5]}]
[["a",1],["b",2],["c",3 ],["d",4],["e",5]]
Подробнее здесь: https://stackoverflow.com/questions/269 ... -json-enco