Removing array index reference when using json_encode()

Use array_values() for your issue:

$arr['dates'] = array_values($arr['dates']);
//..
$arr = json_encode($arr);

Why? Because you’re unsetting array’s key without re-ordering it. So after this the only way to keep that in JSON will be encode keys too. After applying array_values(), however, you’ll get ordered keys (starting from 0) which can be encoded properly without including keys.

Leave a Comment