$a = array("pear","apple","apple","ball","cat");
$u = array_unique($a);
echo json_encode($u);
The output appears as: {"0":"pear","1":"apple","3":"ball","4":"cat"}
I need a non-associative array as output as: ["apple","ball","cat","pear"].
Reindex the array with array_values
before encoding it:
echo json_encode(array_values($u));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With