Jump to content

Hellos

New Members
  • Posts

    5
  • Joined

  • Last visited

Hellos's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @Barandone more thing, How do I get the data of the values in condition? Because it is an array in array Thanks
  2. It works now, you have to use concatenation. Thanks
  3. <?php //echo $character->is_day . '<br>'; $url = '{"location":{"name":"London","region":"City of London, Greater London","country":"United Kingdom","lat":51.52,"lon":-0.11,"tz_id":"Europe/London","localtime_epoch":1672618641,"localtime":"2023-01-02 0:17"},"current":{"last_updated_epoch":1672618500,"last_updated":"2023-01-02 00:15","temp_c":8.0,"temp_f":46.4,"is_day":0,"condition":{"text":"Light rain","icon":"//cdn.weatherapi.com/weather/64x64/night/296.png","code":1183},"wind_mph":4.3,"wind_kph":6.8,"wind_degree":220,"wind_dir":"SW","pressure_mb":1009.0,"pressure_in":29.8,"precip_mm":0.0,"precip_in":0.0,"humidity":93,"cloud":25,"feelslike_c":7.0,"feelslike_f":44.7,"vis_km":10.0,"vis_miles":6.0,"uv":1.0,"gust_mph":5.8,"gust_kph":9.4}}'; $data = file_get_contents($url); // put the contents of the file into a variable $characters = json_decode($data); // decode the JSON feed foreach ($characters as $character) { //location $name = $character->name; $region = $character->region; $country = $character->country; $lat = $character->lat; $lon = $character->lon; $tz_id = $character->tz_id; $localtime_epoch = $character->localtime_epoch; $localtime = $character->localtime; echo$name; } ?> Here is the full code. Thanks
  4. $data = file_get_contents($url); // put the contents of the file into a variable $characters = json_decode($data); // decode the JSON feed foreach ($characters as $character) { //location $name = $character->name; $region = $character->region; $country = $character->country; $lat = $character->lat; $lon = $character->lon; $tz_id = $character->tz_id; $localtime_epoch = $character->localtime_epoch; $localtime = $character->localtime; } echo$name; ?> This is my code and name will not echo the content. $data = file_get_contents($url); // put the contents of the file into a variable $characters = json_decode($data); // decode the JSON feed foreach ($characters as $character) { //location $name = $character->name; $region = $character->region; $country = $character->country; $lat = $character->lat; $lon = $character->lon; $tz_id = $character->tz_id; $localtime_epoch = $character->localtime_epoch; $localtime = $character->localtime; echo$name; } ?> The variable name will output correctly here. Does anyone know what the problem is. Is it to do with variable scopes like global, static or something? Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.