I’ve encoded an Array I’ve made using the inbuilt json_encode(); function. I need it in the format of an Array of Arrays like so:
[["Afghanistan",32,12],["Albania",32,12]]
However, it is returning as:
{"2":["Afghanistan",32,12],"4":["Albania",32,12]}
How can I remove these row numbers without using any regex trickery?
If the array keys in your PHP array are not consecutive numbers,
json_encode()must make the other construct an object since JavaScript arrays are always consecutively numerically indexed.Use
array_values()on the outer structure in PHP to discard the original array keys and replace them with zero-based consecutive numbering:Example: