title: How do i display the NESTED JSON data using php?
body: <p>I coding a whole day just to display the nested Data from JSON that i got from the Api Provider but nothings gonna change. It's always error! what should i do?
  Here's my code hope you help me in this problem.</p>
  <p>Imagine my name of json file is <strong>05-03-21.json</strong>.
  and here's the JSON Data</p>
  <pre><code>    {
     &quot;result&quot;:&quot;OK&quot;,
     &quot;data&quot;:{
        &quot;body&quot;:{
           &quot;header&quot;:&quot;Manila, National Capital Region, Philippines&quot;,
           &quot;query&quot;:{
              &quot;destination&quot;:{
                 &quot;id&quot;:&quot;1004070&quot;,
                 &quot;value&quot;:&quot;Manila, National Capital Region, Philippines&quot;,
                 &quot;resolvedLocation&quot;:&quot;CITY:1004070:UNKNOWN:UNKNOWN&quot;
              }
           },
           &quot;searchResults&quot;:{
              &quot;totalCount&quot;:1286,
              &quot;results&quot;:[
                 {
                    &quot;id&quot;:438619,
                    &quot;name&quot;:&quot;OYO 653 Rosas Garden Hotel&quot;,
                    &quot;starRating&quot;:3,
                    &quot;urls&quot;:[
                       
                    ],
                    &quot;address&quot;:{
                       &quot;streetAddress&quot;:&quot;1140 MH Del Pilar St., Ermita&quot;,
                       &quot;extendedAddress&quot;:&quot;&quot;,
                       &quot;locality&quot;:&quot;Manila&quot;,
                       &quot;postalCode&quot;:&quot;1000&quot;,
                       &quot;region&quot;:&quot;Manila&quot;,
                       &quot;countryName&quot;:&quot;Philippines&quot;,
                       &quot;countryCode&quot;:&quot;ph&quot;,
                       &quot;obfuscate&quot;:false
                    },
                    &quot;welcomeRewards&quot;:{
                       &quot;collect&quot;:true
                    },
                    &quot;guestReviews&quot;:{
                       &quot;unformattedRating&quot;:7,
                       &quot;rating&quot;:&quot;7.0&quot;,
                       &quot;total&quot;:29,
                       &quot;scale&quot;:10,
                       &quot;badge&quot;:&quot;good&quot;,
                       &quot;badgeText&quot;:&quot;Good&quot;
                    },
                    &quot;landmarks&quot;:[
                       {
                          &quot;label&quot;:&quot;City centre&quot;,
                          &quot;distance&quot;:&quot;2.0 km&quot;
                       },
                       {
                          &quot;label&quot;:&quot;Manila Bay&quot;,
                          &quot;distance&quot;:&quot;7.6 km&quot;
                       }
                    ],
                    &quot;geoBullets&quot;:[
                       
                    ],
                    &quot;ratePlan&quot;:{
                       &quot;price&quot;:{
                          &quot;current&quot;:&quot;P1,287&quot;,
                          &quot;exactCurrent&quot;:1286.71,
                          &quot;old&quot;:&quot;P2,383&quot;,
                          &quot;summary&quot;:&quot;excluding taxes &amp; fees&quot;
                       },
                       &quot;features&quot;:{
                          &quot;freeCancellation&quot;:false,
                          &quot;paymentPreference&quot;:false,
                          &quot;noCCRequired&quot;:false
                       },
                       &quot;type&quot;:&quot;EC&quot;
                    },
                    &quot;neighbourhood&quot;:&quot;Ermita&quot;,
                    &quot;deals&quot;:{
                       &quot;specialDeal&quot;:{
                          &quot;dealText&quot;:&quot;Save 46%&quot;
                       },
                       &quot;priceReasoning&quot;:&quot;DRR-446&quot;
                    },
                    &quot;messaging&quot;:[
                       
                    ],
                    &quot;badging&quot;:[
                       
                    ],
                    &quot;pimmsAttributes&quot;:&quot;DoubleStamps|D13|TESCO&quot;,
                    &quot;coordinate&quot;:{
                       &quot;lat&quot;:14.578154,
                       &quot;lon&quot;:120.979947
                    },
                    &quot;providerType&quot;:&quot;LOCAL&quot;,
                    &quot;supplierHotelId&quot;:6457589,
                    &quot;isAlternative&quot;:false,
                    &quot;optimizedThumbUrls&quot;:{
                       &quot;srpDesktop&quot;:&quot;https:\/\/thumbnails.trvl-media.com\/uQm5oEf1djKsihiqX24-TfWhriQ=\/250x140\/smart\/filters:quality(60)\/images.trvl-media.com\/hotels\/7000000\/6460000\/6457600\/6457589\/b189dd23_z.jpg&quot;
                    }
                 },
                 {
                    &quot;id&quot;:756613600,
                    &quot;name&quot;:&quot;Astrotel Anonas&quot;,
                    &quot;starRating&quot;:3,
                    &quot;urls&quot;:[
                       
                    ],
                    &quot;address&quot;:{
                       &quot;streetAddress&quot;:&quot;960 Aurora Boulevard&quot;,
                       &quot;extendedAddress&quot;:&quot;near LRT Anonas Station&quot;,
                       &quot;locality&quot;:&quot;Quezon City&quot;,
                       &quot;postalCode&quot;:&quot;&quot;,
                       &quot;region&quot;:&quot;&quot;,
                       &quot;countryName&quot;:&quot;Philippines&quot;,
                       &quot;countryCode&quot;:&quot;ph&quot;,
                       &quot;obfuscate&quot;:false
                    },
                    &quot;welcomeRewards&quot;:{
                       &quot;collect&quot;:true
                    },
                    &quot;guestReviews&quot;:{
                       &quot;unformattedRating&quot;:4.8,
                       &quot;rating&quot;:&quot;4.8&quot;,
                       &quot;total&quot;:40,
                       &quot;scale&quot;:10
                    },
                    &quot;landmarks&quot;:[
                       {
                          &quot;label&quot;:&quot;City centre&quot;,
                          &quot;distance&quot;:&quot;10 km&quot;
                       },
                       {
                          &quot;label&quot;:&quot;Manila Bay&quot;,
                          &quot;distance&quot;:&quot;17 km&quot;
                       }
                    ],
                    &quot;geoBullets&quot;:[
                       
                    ],
                    &quot;ratePlan&quot;:{
                       &quot;price&quot;:{
                          &quot;current&quot;:&quot;P1,295&quot;,
                          &quot;exactCurrent&quot;:1294.64,
                          &quot;summary&quot;:&quot;excluding taxes &amp; fees&quot;
                       },
                       &quot;features&quot;:{
                          &quot;freeCancellation&quot;:false,
                          &quot;paymentPreference&quot;:false,
                          &quot;noCCRequired&quot;:false
                       },
                       &quot;type&quot;:&quot;EC&quot;
                    },
                    &quot;neighbourhood&quot;:&quot;Quezon City&quot;,
                    &quot;deals&quot;:[
                       
                    ],
                    &quot;messaging&quot;:[
                       
                    ],
                    &quot;badging&quot;:[
                       
                    ],
                    &quot;pimmsAttributes&quot;:&quot;DoubleStamps|D13|TESCO&quot;,
                    &quot;coordinate&quot;:{
                       &quot;lat&quot;:14.627763,
                       &quot;lon&quot;:121.06376
                    },
                    &quot;providerType&quot;:&quot;LOCAL&quot;,
                    &quot;supplierHotelId&quot;:23612925,
                    &quot;isAlternative&quot;:false,
                    &quot;optimizedThumbUrls&quot;:{
                       &quot;srpDesktop&quot;:&quot;https:\/\/thumbnails.trvl-media.com\/0GhZSM5K0XRDs9aaIYn2FuUBUqk=\/250x140\/smart\/filters:quality(60)\/images.trvl-media.com\/hotels\/24000000\/23620000\/23613000\/23612925\/c83bf0b0_z.jpg&quot;
                    }
                 }
              ]
           },
           &quot;common&quot;:{
              &quot;pointOfSale&quot;:{
                 &quot;numberSeparators&quot;:&quot;,.&quot;,
                 &quot;brandName&quot;:&quot;Hotels.com&quot;
              },
              &quot;tracking&quot;:{
                 &quot;omniture&quot;:{
                    &quot;s.prop33&quot;:&quot;D=v33&quot;,
                    &quot;s.prop32&quot;:&quot;D=v43&quot;,
                    &quot;s.prop74&quot;:&quot;search result with dates | ms shown | N&quot;,
                    &quot;s.products&quot;:&quot;MULTISOURCE;6457589,LOCAL;23612925,LOCAL;23612485&quot;,
                    &quot;s.eVar16&quot;:&quot;Mob :: aApp&quot;,
                    &quot;s.eVar40&quot;:&quot;D=v0&quot;,
                    &quot;s.eVar41&quot;:&quot;PHP&quot;,
                    &quot;s.eVar63&quot;:&quot;60acf7e5-d622-4a1a-8110-a1fac036b405&quot;,
                    &quot;s.eVar42&quot;:&quot;30|1|20210404|20210405&quot;,
                    &quot;s.eVar4&quot;:&quot;|SI:anonymous|VS:returnVisitor|HCR:notApplicable|FC:notApplicable|NS:unknown|TI:notApplicable|SM:notApplicable|IR:anonymous|&quot;,
                    &quot;s.eVar43&quot;:&quot;en_PH|HCOM_PH|ph.hotels.com&quot;,
                    &quot;s.eVar3&quot;:&quot;2|0&quot;,
                    &quot;s.eVar22&quot;:&quot;5|PHP|24:438619:2382.7900:1286.7100:1|24:756613600:1294.6400:1294.6400:0|24:756599520:1294.6400:1294.6400:0|24:2052351936:1442.6200:1298.3600:0|24:454367:2407.3200:1299.9500:0&quot;,
                    &quot;s.eVar2&quot;:&quot;Manila, National Capital Region, Philippines&quot;,
                    &quot;s.eVar23&quot;:&quot;5|PHP|24:1279267456:1446.4300:1301.7900:0|24:632077728:2176.8300:1306.1000:1|24:494528:1455.3600:1309.8200:0|24:633744:1311.4800:1311.4800:0|24:1841636192:1311.4800:1311.4800:0&quot;,
                    &quot;s.eVar24&quot;:&quot;MCTC=20;TU=NA;PDID=NULL;MVT=&quot;,
                    &quot;s.eVar7&quot;:&quot;30&quot;,
                    &quot;s.server&quot;:&quot;ph.hotels.com&quot;,
                    &quot;s.eVar6&quot;:&quot;1004070&quot;,
                    &quot;s.prop29&quot;:&quot;D=v42&quot;,
                    &quot;s.eVar5&quot;:&quot;1&quot;,
                    &quot;s.prop27&quot;:&quot;1f6f9be9-a413-4f39-874c-86385cfe9627&quot;,
                    &quot;s.eVar9&quot;:&quot;Price - low to high&quot;,
                    &quot;s.prop21&quot;:&quot;0&quot;,
                    &quot;s.prop20&quot;:&quot;2&quot;,
                    &quot;s.eVar69&quot;:&quot;Mob :: aApp&quot;,
                    &quot;s.currencyCode&quot;:&quot;PHP&quot;,
                    &quot;s.eVar26&quot;:&quot;US:NY:NEWYORK:501&quot;,
                    &quot;s.eVar29&quot;:&quot;Mob :: aApp&quot;,
                    &quot;s.prop9&quot;:&quot;1286&quot;,
                    &quot;s.eVar95&quot;:&quot;Unknown&quot;,
                    &quot;s.prop7&quot;:&quot;1252&quot;,
                    &quot;s.eVar31&quot;:&quot;D=v0&quot;,
                    &quot;s.eVar32&quot;:&quot;D=v0&quot;,
                    &quot;s.eVar33&quot;:&quot;search result with dates&quot;,
                    &quot;s.eVar34&quot;:&quot;H1871:007.002,M376:152.000,M904:000.000,M3736:000.000,M4200:000.000,M4440.2,M4869:001.000,M4952:036.001,M4961:001.000,M5184:001.000,M5342:000.000,M5663:000.000,M6388:000.000,M6775:000.000,M6779:000.000,M7015.1,M7192:000.000,M7215:000.000,M7296:000.000,M7305:000.000,M7353:000.000,M7362.0,M7384:000.000,M7552:023.001,M7561:000.000,M7763:000.000,M7765.2,M7870:000.000,M7895:000.000,M8336:000.000,M8347:019.002,M8483:000.000,M8485:007.001,M8692:000.000,M8693:000.000,M8698:000.000,M8708:000.000,M8714:000.000,M8718:000.000,M8758:000.000,M8915:000.000,M8928:000.000,M8952:000.000,M8954:000.000,M8976:000.000,M8992:000.000,M9004:000.000,M9035:000.000,M9065:000.000,M9220:000.000,M9281:000.000,M9282:000.000,M9297:000.000,M9301:000.000,M9351:000.000,M9420:000.000,M9431:000.000,M9469:000.000,M9549:000.000,M9567.1,M9691:000.000,M9693:000.000,M9699:000.000,M9716:000.000,M9729:000.000,M9752:000.000,M9771:000.000,M9853:000.000,M9857:000.000,M9864:000.000,M9924:000.000,M9927:000.000,M9945:000.000,M9961:000.000,M9971:000.000,M10001:000.000,M10007:000.000,M10010:000.000,M10013:002.001,M10068:000.000,M10121:000.000,M10125:000.000,M10137:001.001,M10148:000.000,M10155:000.000,M10248:000.000,M9215:001.000&quot;,
                    &quot;s.eVar13&quot;:&quot;389242&quot;,
                    &quot;s.prop19&quot;:&quot;1&quot;,
                    &quot;s.events&quot;:&quot;event324,event319,event320&quot;,
                    &quot;s.prop18&quot;:&quot;D=v6&quot;,
                    &quot;s.prop5&quot;:&quot;389242&quot;,
                    &quot;s.prop15&quot;:&quot;1&quot;,
                    &quot;s.prop3&quot;:&quot;Manila, National Capital Region, Philippines&quot;,
                    &quot;s.prop14&quot;:&quot;D=v7&quot;,
                    &quot;s.prop36&quot;:&quot;|SI:anonymous|VS:returnVisitor|HCR:notApplicable|FC:notApplicable|NS:unknown|TI:notApplicable|SM:notApplicable|IR:anonymous|&quot;,
                    &quot;s.eVar93&quot;:&quot;aws.us-west-2.unknown&quot;,
                    &quot;s.prop2&quot;:&quot;Price - low to high&quot;
                 }
              }
           }
        }
     }
  }
  </code></pre>
  <p>And here's my php code.</p>
  <pre><code>                &lt;?php  
  
                  $filepath = '05-03-21.json'; 
                  $json_string = file_get_contents($filepath); 
                  $json_data = json_decode($json_string,true); 
  
                  $json_data = json_decode($json_string,true); 
                  foreach ($json_data as $var_1 ) {
                      foreach ($var_1['searchResults'] as $var_2 ) {
                          echo &quot;Hotel Name: &quot;.$var_2['name'].&quot;&lt;br&gt;&quot;;
                          echo &quot;Ratings: &quot;.$var_2['starRating'].&quot;&lt;br&gt;&quot;;
                          echo &quot;Location: &quot;.$var_2['address']['locality'].&quot;&lt;br&gt;&quot;;
                      }
  
                  }
  
              ?&gt;
  </code></pre>
  <p>All i wanna do is to display the Data with loop something like this.
  <a href="https://i.stack.imgur.com/yZRmy.png" rel="nofollow noreferrer">Image here</a></p>