0

I'm new to php, so sorry about trivial question...

I have this JSON:

{"data":{"summary":{"records":67,"page":1,"total":67,"hasMore":0},"reservations":[{"id":1111111,"property":"villadianna","from":"2016-07-18","to":"2016-07-25"},"pricing":{"price":1164.2400,"currency":"EUR","retail":1323},"clientInfo":{"firstName":"pera","lastName":"peric","email":"myemail@gmail.com"},"status":1,"offline":0},{"id":222222,"property":"villadianna", etc. ... ...

How I can make foreach and create an table row for each reservation ID ?

now I have just:

echo $result;
Aleks Per
  • 1,549
  • 7
  • 33
  • 68

1 Answers1

1

You can try this:

$json = json_decode($yourJson);
foreach ($json as $element) {
  print_r($element);
}
// In case you need to access a specific property
// $json->property

Each element will be an object.

You can use json_decode($yourJson, true); to get an array instead of the object.

More info here: http://php.net/manual/es/function.json-decode.php

Salvador P.
  • 1,469
  • 19
  • 16
  • please help to consctruct html as an table – Aleks Per Jul 13 '16 at 13:51
  • Execute the code is pretty straightforward. You'll need a valid json string. You can access the reservations property directly. See the code. For the html table you can use some loops and the html tag.
    – Salvador P. Jul 13 '16 at 14:38
  • Please take a look at the code and the comments, it's there ;). You can use $json->reservations, and use loops. – Salvador P. Jul 13 '16 at 18:29