I have the following PHP array:
array("Apple", "Pear", "Grape", "Orange")
And I'd like to get JSON output like the following:
[[{"fruit":"Apple"}],[{"fruit":"Pear"}],[{"fruit":"Grape"}],[{"fruit":"Orange"}]]
JSON confuses me :(
EDIT Sorry, those last two in the output should have been fruit, I corrected it, sorry guys.
If you want your JSON output to look like that, you should change your PHP value to look like this:
array(array(array('fruit' => 'Apple')), array(array('fruit' => 'Pear')), array(array('fruit' => 'Grape')), array(array('fruit' => 'Orange')))
and then pass that array to json_encode()
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