Aleks Per
Aleks Per

Reputation: 1639

How to create valid array from JSON to use it at foreach loop

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":"[email protected]"},"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 ?

Upvotes: 0

Views: 44

Answers (1)

Matt Wisniewski
Matt Wisniewski

Reputation: 91

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

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

Upvotes: 1

Related Questions