I am new to arrays but I’m trying to achieve the following:
{
"Basic": "91919191",
"Info": [
{
"ID": 1,
"Extra": 3
},
{
"ID": 2,
"Extra": 6
}, etc etc..
]
}
But instead I get double array like this:
{
"Basic": "91919191",
"Info": [
[
{
"ID": 1,
"Extra": 3
},
{
"ID": 2,
"Extra": 6
}, etc etc..
]
]
}
Here is the code I am currently using
$first = array();
$first['Basic'] = "91919191";
$x = 1;
while ($x <= 3) {
$y = $x * 3;
$second[] = array('ID' => $x, 'Extra' => $y);
$x++;
}
$first['Info'] = array($second);
echo json_encode($first, JSON_PRETTY_PRINT);
I’ve tried using array_merge but the results are not as expected. Any ideas/suggestions?