I am combining two arrays then encoding into JSON for output. I get a funky value in JSON output at the start of the second array. This is the "0": item. I can’t figure out where this is coming from.
Combine the arrays and output json:
$combine = array_merge(array('array1'=>$bay_events, array('array2'=>$key_events)));
$finish = json_encode($combine);
$callback = $_GET['callback'];
echo $callback.$finish;
JSON output:
{
"array1": [
{
"event_id": "3914",
"event_name": "Test"
}
],
"0": { <--- this should not be here
"array2": [
{
"event_id": "3913",
"event_name": "Testssdgs This Is how"
}
]
}
}
I cant figure out where "0": is coming from. Help?
You are not using
array_mergethe proper wayThe problem
0Explanation
This is the proper way to use
array_mergeOr Just remove it totally