For example, if I make something like this:
<?php
//first json object
$cars[] = "1";
$cars[] = "2";
$cars[] = "3";
$cars[] = "4";
//second json object
$cars[] = "22";
$cars[] = "33";
$cars[] = "44";
$cars[] = "55";
//now i need to add them to the json array "cars"
echo json_encode(array("cars" => $cars));
?>
The output will become :
{"cars":["1","2","3","4"]}
However, I want it to be:
{
"cars": [
{"1", "2", "3", "4"},
{"22", "33", "44", "55"}
]
}
EDIT (editing my old questions):
First of all, the result i wanted is not a valid JSON.
It has to be something like this:
{
"cars": [
["1", "2", "3", "4"],
["22", "33", "44", "55"]
]
}
In order to get the above result, simply do the following:
The entire code:
<?php
// Add the first car to the array "cars":
$car = array("1","2","3","4");
$cars[] = $car;
// Add the second car to the array "cars":
$car = array("22","33","44","55");
$cars[] = $car;
//Finally encode using json_encode()
echo json_encode(array("cars" => $cars));
?>
{"22","33","44","55"}
piece.