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":"[email protected]"},"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;
5
  • Just decode it to an array. Commented Jul 13, 2016 at 13:44
  • please make an example Commented Jul 13, 2016 at 13:46
  • please google it and research it. Commented Jul 13, 2016 at 13:47
  • use json decode, var_dump(json_decode($json)); Commented Jul 13, 2016 at 13:49
  • 1
    Possible duplicate of Parsing JSON file with PHP Commented Jul 13, 2016 at 13:59

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

please help to consctruct html as an table
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 <table> tag.
Please take a look at the code and the comments, it's there ;). You can use $json->reservations, and use loops.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.