3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Weather { /** * service properties */ public $attributes; /** * constant definitions (forecast mode) */ const MARINE = "marine"; const MOUNTAIN = "ski"; const WEATHER = "weather"; /** * constructor for this class * @param string $key the API key for this element * @return mixed an instance of this class * @example $weather = new \Services\Information\Weather(); * @example $weather = new \Services\Information\Weather("sample key"); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function __construct($key = "ad14d73de30ee62b02aa6022a1b2d") { $this->attributes["key"] = $key; $this->attributes["mode"] = self::WEATHER; return $this; } /** * returns the date (in ISO format) for this element * @return string the date (in ISO format) for this element * @example $date = $weather->getDate(); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function getDate() { if (!empty($this->attributes["date"])) { return $this->attributes["date"]; } } /** * returns the number of forecasting days for this element * @return numeric the number of forecasting days for this element * @example $days = $weather->getDays(); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function getDays() { if (!empty($this->attributes["days"])) { return $this->attributes["days"]; } } /** * returns the API key for this element * @return string the API key for this element * @example $key = $weather->getKey(); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function getKey() { if (!empty($this->attributes["key"])) { return $this->attributes["key"]; } } /** * returns the location for this element * @return mixed the location for this element * @example $location = $weather->getLocation(); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function getLocation() { if (!empty($this->attributes["location"])) { return $this->attributes["location"]; } } /** * returns the forecasting mode for this element * @return mixed the forecasting mode for this element * @example $mode = $weather->getMode(); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function getMode() { if (!empty($this->attributes["mode"])) { return $this->attributes["mode"]; } } /** * returns the list of parameters for this element * @return string the list of URL request parameters for this element * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function getParameters() { if (!empty($this->attributes)) { $parameters[] = "format=json"; if (!empty($this->attributes["location"])) { $parameters[] = "q=" . urlencode($this->attributes["location"]); } if (!empty($this->attributes["days"])) { $parameters[] = "num_of_days=" . $this->attributes["days"]; } if (!empty($this->attributes["date"])) { $parameters[] = "date=" . $this->attributes["date"]; } if (!empty($this->attributes["key"])) { $parameters[] = "key=" . $this->attributes["key"]; } return "?" . implode("&", $parameters); } } /** * sets the number of forecasting days for this element * @param numeric $days the number of forecasting days for this element * @example $weather->setDays(3); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function setDays($days) { if (!empty($days)) { if (is_numeric($days)) { if ($days > 0) { $this->attributes["days"] = $days; } } } return $this; } /** * sets the API key for this element * @param string $key the API key for this element * @example $weather->setKey("sample key"); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function setKey($key) { if (!empty($key)) { $this->attributes["key"] = $key; } return $this; } /** * sets the location for this element * @param mixed $data the input data for this element (either the latitude/longitude pair or the city name) * @example $weather->setLocation(39.607679, 2.869080); * @example $weather->setLocation("palma"); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function setLocation() { if (!empty($arguments = func_get_args())) { if (!empty($count = func_num_args())) { if ($count > 1) { if (!empty($latitude = current($arguments))) { if (!empty($longitude = next($arguments))) { if (is_numeric($latitude)) { if (is_numeric($longitude)) { $this->attributes["location"] = [$latitude, $longitude]; } } } } } elseif ($count > 0) { if (!empty($location = current($arguments))) { if (!is_numeric($location)) { $this->attributes["location"] = $location; } } } } } return $this; } /** * sets the forecast mode for this element * @param string $mode the forecast mode for this element * @example $weather->setMode(\Services\Information\Weather::MARINE); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function setMode($mode) { if (!empty($mode)) { if (in_array($mode, [ self::MARINE, self::MOUNTAIN, self::WEATHER ], true)) { $this->attributes["mode"] = $mode; } } return $this; } /** * outputs this element * @return mixed the weather forecasting data for this element * @example $data = $weather->output(); * @version 1.0 * @author Julio Meca Hansen <jmecahansen@gmail.com> */ public function output() { $output = false; if (!empty($this->attributes["mode"])) { if (in_array($this->attributes["mode"], [ self::MARINE, self::MOUNTAIN, self::WEATHER ], true)) { if (!empty($this->attributes["key"])) { if (!empty($this->attributes["location"])) { if (!empty($this->attributes["days"])) { if (!empty($c = curl_init(\Helpers\URL::getProtocol() . "://api.worldweatheronline.com/free/v2/{$this->attributes["mode"]}.ashx{$this->getParameters()}"))) { curl_setopt($c, CURLOPT_HEADER, false); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); if (!empty($input = json_decode(curl_exec($c), true))) { if (!empty($input["data"])) { $codes = [ 113 => _("soleado"), 116 => _("parcialmente nublado"), 119 => _("nublado"), 122 => _("nublado"), 143 => _("bruma"), 176 => _("lluvia irregular"), 179 => _("nieve irregular"), 182 => _("aguanieve irregular"), 185 => _("congelación irregular"), 200 => _("nublado con posibilidad de tormenta"), 227 => _("nevada con viento ligero"), 230 => _("tormenta de nieve"), 248 => _("niebla"), 260 => _("niebla helada"), 263 => _("nublado con llovizna"), 266 => _("llovizna"), 281 => _("llovizna con helada"), 284 => _("llovizna fuerte con helada"), 293 => _("nublado con lluvia ligera"), 296 => _("lluvia ligera"), 299 => _("lluvia moderada esporádica"), 302 => _("lluvia moderada"), 305 => _("lluvia fuerte esporádica"), 308 => _("lluvia fuerte"), 311 => _("lluvia ligera con helada"), 314 => _("lluvia moderada o fuerte con helada"), 317 => _("aguanieve ligera"), 320 => _("aguanieve moderada o fuerte"), 323 => _("nublado con nevada ligera"), 326 => _("nevada ligera"), 329 => _("nublado con nevada moderada"), 332 => _("nevada moderada"), 335 => _("nublado con nevada fuerte"), 338 => _("nevada fuerte"), 350 => _("granizo"), 353 => _("episodios de lluvia ligera"), 356 => _("episodios de lluvia moderada o fuerte"), 359 => _("lluvia torrencial"), 362 => _("episodios de aguanieve ligera"), 365 => _("episodios de aguanieve moderada o fuerte"), 368 => _("episodios de nieve ligera"), 371 => _("episodios de nieve moderada o fuerte"), 374 => _("episodios de granizo ligera"), 377 => _("episodios de granizo moderada o fuerte"), 386 => _("nublado con lluvia ligera y truenos"), 389 => _("nevada moderada o fuerte con tormenta"), 392 => _("nublado con nevada ligera y truenos"), 395 => _("nevada moderada o fuerte con tormenta") ]; if ($this->attributes["mode"] === self::MARINE) { print_r($input["data"]); } elseif ($this->attributes["mode"] === self::MOUNTAIN) { print_r($input["data"]); } elseif ($this->attributes["mode"] === self::WEATHER) { if (!empty($input["data"]["weather"])) { foreach ($input["data"]["weather"] as $forecast) { $output["forecast"][] = [ "date" => $forecast["date"], "temperature" => [ "minimum" => [ "C" => $forecast["mintempC"], "F" => $forecast["mintempF"], ], "maximum" => [ "C" => $forecast["maxtempC"], "F" => $forecast["maxtempF"], ] ], "details" => array_map(function ($i) use ($codes) { return [ "cloudcover" => $i["cloudcover"], "description" => [ "code" => $i["weatherCode"], "text" => $codes[$i["weatherCode"]] ], "humidity" => $i["humidity"], "precipitation" => $i["precipMM"], "pressure" => $i["pressure"], "temperature" => [ "felt" => [ "C" => $i["FeelsLikeC"], "F" => $i["FeelsLikeF"], ], "measured" => [ "C" => $i["tempC"], "F" => $i["tempF"], ] ], "time" => str_pad($i["time"] / 100, 2, "0", STR_PAD_LEFT) . ":00", "visibility" => $i["visibility"], "wind" => [ "angle" => $i["winddirDegree"], "direction" => $i["winddir16Point"], "speed" => [ "kilometers" => $i["windspeedKmph"], "miles" => $i["windspeedMiles"] ] ] ]; }, $forecast["hourly"]) ]; } } } } } } } } } } } return $output; } } $w = new Weather(); $w->setLocation("Palma"); $w->setDays(3); $w->setMode(Weather::MARINE); print_r($w->output()); ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.70.0130.00618.43
8.3.60.0110.00417.00
8.3.50.0080.00921.29
8.3.40.0150.00019.14
8.3.30.0070.00718.96
8.3.20.0000.00920.32
8.3.10.0040.00421.85
8.3.00.0080.00019.79
8.2.180.0070.01318.66
8.2.170.0000.01522.96
8.2.160.0110.00320.65
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0000.01017.75
8.2.110.0040.00720.66
8.2.100.0060.00617.75
8.2.90.0000.00819.30
8.2.80.0040.00417.97
8.2.70.0090.00017.75
8.2.60.0000.00818.05
8.2.50.0060.00318.07
8.2.40.0030.00621.06
8.2.30.0000.00819.91
8.2.20.0040.00417.98
8.2.10.0000.00818.20
8.2.00.0000.00818.35
8.1.280.0100.00725.92
8.1.270.0060.00320.52
8.1.260.0050.00526.35
8.1.250.0000.01028.09
8.1.240.0030.00623.88
8.1.230.0080.00417.42
8.1.220.0030.00517.74
8.1.210.0030.00718.77
8.1.200.0070.00317.37
8.1.190.0060.00317.34
8.1.180.0030.00518.10
8.1.170.0030.00518.83
8.1.160.0060.00322.16
8.1.150.0070.00419.09
8.1.140.0030.00617.48
8.1.130.0050.00217.91
8.1.120.0000.00717.54
8.1.110.0070.00317.63
8.1.100.0000.00817.68
8.1.90.0000.00817.61
8.1.80.0040.00717.64
8.1.70.0030.00317.62
8.1.60.0030.00617.76
8.1.50.0060.00317.73
8.1.40.0060.00317.65
8.1.30.0030.00517.72
8.1.20.0030.00617.80
8.1.10.0080.00017.73
8.1.00.0080.00017.67
8.0.300.0000.00818.77
8.0.290.0040.00417.00
8.0.280.0030.00318.60
8.0.270.0050.00317.43
8.0.260.0000.01117.30
8.0.250.0040.00417.21
8.0.240.0000.00717.19
8.0.230.0000.00717.00
8.0.220.0000.00717.16
8.0.210.0030.00317.04
8.0.200.0030.00317.23
8.0.190.0040.00417.02
8.0.180.0040.00417.18
8.0.170.0060.00317.11
8.0.160.0000.00717.02
8.0.150.0000.00717.04
8.0.140.0040.00417.13
8.0.130.0030.00313.52
8.0.120.0030.00617.14
8.0.110.0000.00816.99
8.0.100.0030.00616.98
8.0.90.0040.00417.15
8.0.80.0030.01317.04
8.0.70.0030.00616.98
8.0.60.0050.00217.20
8.0.50.0000.00817.02
8.0.30.0060.01117.08
8.0.20.0140.00617.40
8.0.10.0070.00017.12
8.0.00.0060.01417.07
7.4.330.0000.00515.08
7.4.320.0050.00316.70
7.4.300.0000.00716.71
7.4.290.0040.00416.82
7.4.280.0000.01016.81
7.4.270.0030.00316.57
7.4.260.0040.00416.68
7.4.250.0060.00316.78
7.4.240.0020.00616.71
7.4.230.0000.00716.77
7.4.220.0060.01216.71
7.4.210.0100.00716.88
7.4.200.0040.00416.56
7.4.160.0090.00616.69
7.4.150.0040.01517.40
7.4.140.0140.01117.86
7.4.130.0070.01116.65
7.4.120.0140.00416.68
7.4.110.0150.00916.61
7.4.100.0090.00916.73
7.4.90.0030.01516.55
7.4.80.0110.00719.39
7.4.70.0110.00716.68
7.4.60.0110.00616.84
7.4.50.0040.00016.65
7.4.40.0070.01116.84
7.4.30.0100.00716.67
7.4.10.0100.01015.10
7.4.00.0050.01015.04
7.3.330.0000.00513.53
7.3.320.0030.00313.61
7.3.310.0000.00716.61
7.3.300.0000.00716.59
7.3.290.0080.00916.56
7.3.280.0070.01016.56
7.3.270.0030.01617.40
7.3.260.0060.01216.52
7.3.250.0090.00816.63
7.3.240.0100.00616.80
7.3.230.0150.00316.73
7.3.210.0070.01016.60
7.3.200.0100.00719.39
7.3.190.0100.00716.51
7.3.180.0220.02216.86
7.3.170.0060.01116.71
7.3.160.0100.01416.61
7.3.130.0110.00715.15
7.3.120.0080.00915.00
7.3.110.0070.01015.11
7.3.100.0080.00715.01
7.3.90.0070.00615.11
7.3.80.0060.00815.09
7.3.70.0060.00814.94
7.3.60.0060.00715.00
7.3.50.0070.01015.02
7.3.40.0020.01115.00
7.3.30.0070.00714.96
7.3.20.0040.01216.73
7.3.10.0050.00916.63
7.3.00.0050.00916.67
7.2.330.0080.01616.66
7.2.320.0070.01016.94
7.2.310.0110.00717.02
7.2.300.0060.01616.67
7.2.290.0110.00716.73
7.2.260.0070.01315.20
7.2.250.0040.01615.30
7.2.240.0090.00715.22
7.2.230.0060.00815.26
7.2.220.0070.00815.17
7.2.210.0050.01115.27
7.2.200.0070.00715.18
7.2.190.0060.00815.22
7.2.180.0060.00915.20
7.2.170.0040.01015.13
7.2.160.0070.00815.17
7.2.150.0060.00716.96
7.2.140.0060.01016.81
7.2.130.0060.00816.83
7.2.120.0070.00816.85
7.2.110.0060.00816.90
7.2.100.0060.00716.91
7.2.90.0070.00916.84
7.2.80.0050.01116.86
7.2.70.0070.00817.01
7.2.60.0080.00816.77
7.2.50.0080.00716.93
7.2.40.0050.01016.92
7.2.30.0010.01216.93
7.2.20.0100.00816.84
7.2.10.0060.00916.96
7.2.00.0070.00717.40
7.1.330.0110.00415.84
7.1.320.0040.01015.74
7.1.310.0040.00915.84
7.1.300.0040.00915.76
7.1.290.0040.00815.88
7.1.280.0050.00715.84
7.1.270.0060.00815.77
7.1.260.0050.00915.87
7.1.250.0090.00815.74
7.1.240.0070.00815.62
7.1.230.0070.00915.84
7.1.220.0070.00815.52
7.1.210.0080.00815.75
7.1.200.0030.01015.79
7.1.190.0060.00715.75
7.1.180.0060.00915.79
7.1.170.0060.00915.77
7.1.160.0050.01115.67
7.1.150.0080.00815.80
7.1.140.0050.00915.85
7.1.130.0080.00715.78
7.1.120.0050.00715.89
7.1.110.0060.01115.86
7.1.100.0060.00516.39
7.1.90.0060.00615.66
7.1.80.0100.00515.74
7.1.70.0060.00816.23
7.1.60.0080.01116.91
7.1.50.0100.00616.22
7.1.40.0060.00915.94
7.1.30.0070.00815.73
7.1.20.0060.00915.70
7.1.10.0040.01115.83
7.1.00.0050.02417.44
7.0.330.0100.00515.40
7.0.320.0100.00615.50
7.0.310.0100.00615.43
7.0.300.0060.00815.26
7.0.290.0060.01015.46
7.0.280.0070.00815.37
7.0.270.0080.00615.33
7.0.260.0060.01115.40
7.0.250.0090.00715.54
7.0.240.0030.00715.48
7.0.230.0060.00815.38
7.0.220.0060.00915.20
7.0.210.0100.00515.38
7.0.200.0030.01015.64
7.0.190.0020.01015.42
7.0.180.0050.00815.48
7.0.170.0110.00515.43
7.0.160.0070.00715.33
7.0.150.0060.00715.32
7.0.140.0080.00715.43
7.0.130.0040.01015.47
7.0.120.0080.00715.61
7.0.110.0040.01015.37
7.0.100.0070.01516.62
7.0.90.0050.01616.57
7.0.80.0050.01716.64
7.0.70.0060.02316.56
7.0.60.0060.02616.51
7.0.50.0080.02416.70
7.0.40.0050.02515.09
7.0.30.0070.02515.04
7.0.20.0030.02915.09
7.0.10.0080.02315.21
7.0.00.0020.02915.14
5.6.400.0050.01014.71
5.6.390.0030.00814.42
5.6.380.0050.01214.55
5.6.370.0080.00614.53
5.6.360.0050.00814.36
5.6.350.0080.00414.58
5.6.340.0060.01014.48
5.6.330.0080.00714.56
5.6.320.0030.00914.48
5.6.310.0090.00514.34
5.6.300.0100.00514.42
5.6.290.0070.00914.56
5.6.280.0070.02216.11
5.6.270.0080.00814.56
5.6.260.0070.00614.58
5.6.250.0050.01416.13
5.6.240.0050.01916.09
5.6.230.0070.02316.05
5.6.220.0080.02215.89
5.6.210.0060.01516.02
5.6.200.0080.02316.11
5.6.190.0070.02616.12
5.6.180.0070.02516.10
5.6.170.0070.02016.13
5.6.160.0060.02616.16
5.6.150.0070.02116.05
5.6.140.0070.01916.11
5.6.130.0090.01716.15
5.6.120.0030.03016.07
5.6.110.0080.02716.08
5.6.100.0070.02616.15
5.6.90.0100.02516.09
5.6.80.0110.02615.93
5.6.70.0080.02615.84
5.6.60.0050.02716.01
5.6.50.0050.02115.81
5.6.40.0090.02515.87
5.6.30.0040.02815.95
5.6.20.0050.02415.83
5.6.10.0070.01915.90
5.6.00.0070.02215.89
5.5.380.0030.01715.21
5.5.370.0060.01715.15
5.5.360.0060.02115.10
5.5.350.0060.02215.36
5.5.340.0020.02615.04
5.5.330.0050.02515.27
5.5.320.0080.02115.27
5.5.310.0100.02215.29
5.5.300.0050.02715.19
5.5.290.0080.02715.32
5.5.280.0060.02715.30
5.5.270.0060.02615.13
5.5.260.0060.02515.19
5.5.250.0030.02914.98
5.5.240.0090.02014.98
5.5.230.0060.02414.86
5.5.220.0050.02314.99
5.5.210.0080.02315.04
5.5.200.0060.02515.04
5.5.190.0040.01714.97
5.5.180.0050.02815.01
5.5.170.0030.00813.44
5.5.160.0060.02415.07
5.5.150.0070.02414.97
5.5.140.0020.02915.02
5.5.130.0040.02715.01
5.5.120.0090.01915.03
5.5.110.0080.02315.15
5.5.100.0110.01615.11
5.5.90.0030.02914.93
5.5.80.0040.02514.94
5.5.70.0060.02615.00
5.5.60.0060.02515.11
5.5.50.0070.02314.96
5.5.40.0080.02314.86
5.5.30.0080.02714.97
5.5.20.0060.02315.13
5.5.10.0090.01914.92
5.5.00.0020.01914.97
5.4.450.0090.02013.34
5.4.440.0030.02713.35
5.4.430.0060.02413.40
5.4.420.0080.02513.34
5.4.410.0070.02513.33
5.4.400.0100.02113.27
5.4.390.0060.02413.32
5.4.380.0050.02213.24
5.4.370.0070.02113.35
5.4.360.0060.02613.34
5.4.350.0070.02113.18
5.4.340.0060.01613.28
5.4.330.0060.00711.37
5.4.320.0060.02313.20
5.4.310.0070.01213.22
5.4.300.0070.02113.26
5.4.290.0060.02213.28
5.4.280.0050.02413.35
5.4.270.0060.02413.24
5.4.260.0040.02513.31
5.4.250.0040.02613.32
5.4.240.0060.02413.25
5.4.230.0050.02413.28
5.4.220.0090.01313.23
5.4.210.0060.02513.28
5.4.200.0060.01913.21
5.4.190.0080.02213.32
5.4.180.0090.02313.23
5.4.170.0040.02013.13
5.4.160.0060.01313.24
5.4.150.0060.01313.14
5.4.140.0040.01312.58
5.4.130.0030.01912.60
5.4.120.0070.01512.58
5.4.110.0030.02212.63
5.4.100.0060.01612.56
5.4.90.0040.02012.55
5.4.80.0070.02212.58
5.4.70.0040.02312.56
5.4.60.0060.02112.59
5.4.50.0070.01312.63
5.4.40.0070.01212.60
5.4.30.0030.02812.54
5.4.20.0050.02312.54
5.4.10.0030.02312.56
5.4.00.0050.02212.39

preferences:
59.36 ms | 401 KiB | 5 Q