Help trying to generate tricky multidimensional array format

arturoriyadh

New Member
I'm having trouble trying to build an array in PHP which will output in the JSON format I am looking for. I will show you what I am trying to achieve and where I have got to so far:\[code\][ {"data":[{"x":3,"y":0},{"x":10,"y":0}]}, {"data":[{"x":11,"y":0},{"x":13,"y":0}]}, {"data":[{"x":12,"y":1},{"x":17,"y":1}]}]\[/code\]I am looping through db results and trying to build arrays to output the above json, my php looks like this (which is obviously not right yet):\[code\]//build the data $data = http://stackoverflow.com/questions/3862584/array( array('x' => $age_start, 'y' => $ill_type ), array( 'x' => $age_end, 'y' => $ill_type ) ); $illnesses[] = $data; \[/code\]This code outputs the following json:\[code\][ { [ [{"x":2,"y":6},{"x":2,"y":6}], [{"x":2,"y":6},{"x":5,"y":6}], [{"x":4,"y":6},{"x":4,"y":6}] ] }]\[/code\]Any pointers on this would be great!
 
Back
Top