0

I have this text ($results):

{"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. ... ...

Now I need to get reserations array and make foreach loop so I try:

...
$result = curl_exec($ch);
curl_close($ch);

$json = json_decode($result);
foreach ($json->reservations as $element) {
  print_r($element);
}

but I get errors: enter image description here

How to create html table with foreach loop only for reservations ?

Aleks Per
  • 1,549
  • 7
  • 33
  • 68
  • 1
    Do a `print_r($json);` and look at the object you are dealing with. `$json->data->reservations` – RiggsFolly Jul 13 '16 at 16:09
  • var_dump() is better, since it'll output booleans properly. – Marc B Jul 13 '16 at 16:12
  • @MarcB Personally hate the output from `var_dump()` only use it if I really have to and `print_r()` does not show enough detail which is rare in my experince but you are probably right – RiggsFolly Jul 13 '16 at 16:14
  • ok I make print_r($json); and I get screen with json as a text – Aleks Per Jul 13 '16 at 16:18
  • So that is what your `$json` object looks like read it and understand its structure. If you read the lables you will see `stdClass` (means an object) or `Array` (means an array) – RiggsFolly Jul 13 '16 at 16:20
  • this is begin of what I got: stdClass Object ( [summary] => stdClass Object ( [records] => 67 [page] => 1 [total] => 67 [hasMore] => 0 ) [reservations] => Array ( [0] => stdClass Object ( [id] => 11616946 – Aleks Per Jul 13 '16 at 16:23
  • if you want to pretty print json: http://stackoverflow.com/a/9120871/3392762 – Progrock Jul 13 '16 at 16:30

1 Answers1

1
...
$result = curl_exec($ch);
curl_close($ch);

$json = json_decode($result);
foreach ($json->data->reservations as $element) {
  print_r($element);
}