I have an array that contains multiple entries of books. I store each books element with its unique id as its key in each. I'm struggling on generating correct JSON from this.
When i json_encode on the array it just generates each sub arrays json not grouping the elements by key but by which array they're in.
this is my multidimensional array
$booksarray = array("book title" => array(), "book isbn" => array(), "book borrowedcount" => array());
Im completely lost how to get elements out of each sub array and then group them together so that they output something like,
{"results":
{"course": "CC120", "books":
{ "book":
[{"id": "12345", "title": "javascript", "isbn": "123456789", "borrowedcount": "45"}] } }
I have the XML outputing as follows
<results>
<course>cc120</course>
<books>
<book id="9876" title="html" isbn="000001234" borrowedcount="56">
<book id="12345" title="javascript" isbn="123456789" borrowedcount="45">
<book id="222" title="php5" isbn="55555555" borrowedcount="22">
<book id="23788" title="XML" isbn="99988877" borrowedcount="5">
</books>
</results>
Any help will be greatly appreciated
json_encode()not work? php.net/manual/en/function.json-encode.php