-2

Model JSON: https://dl.dropboxusercontent.com/s/vjq9j5gwkbrly3y/data.json

How can I generate the above JSON using PHP, including the separate categories in to the above model?

I need help to separate the above categories for JSON. Do I have to do several selects?

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
  • Not sure what you mean by do i have to do several selects....as you're not mentioning MYSQL at all , youre asking how to generate JSON with php – Kylie Jun 27 '14 at 22:01

1 Answers1

2

Just build your arrays,

    $array = array("Restaurants"=>array(
      array("ID"=>23,"name"=>"test","example"=>"ex"),
      array("ID"=>23,"name"=>"test","example"=>"ex"),
      array("ID"=>23,"name"=>"test","example"=>"ex")
     ),
    "Categories"=>array(
      array("cat"=>"example","ex"=>"example"),
      array("cat"=>"example","ex"=>"example")
     )
     );

Then use json_encode

    echo json_encode($array);

EXAMPLE

Kylie
  • 11,421
  • 11
  • 47
  • 78