3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Container implements ArrayAccess, Countable, Iterator, JsonSerializable, Serializable { protected $values; public function __construct(... $values) { $this->values = []; foreach ($values as $value) { if (is_array($value)) { foreach ($value as $val) { $this->append($val); } } else { $this->append($value); } } } protected function validate($value) { return true; } protected function format($value) { return $value; } public function prepend($value) { if ($this->validate($value)) { array_unshift($this->values, $this->format($value)); return true; } return false; } public function shift() { return array_shift($this->values); } public function append($value) { if ($this->validate($value)) { array_push($this->values, $this->format($value)); return true; } return false; } public function pop() { return array_pop($this->values); } public function toArray() { return $this->values; } public function filter($callback) { $this->values = array_values(array_filter($this->values, $callback)); return $this; } public function map($callback) { $this->values = array_values(array_map([$this, 'format'], array_filter(array_map($callback, $this->values), [$this, 'validate']))); return $this; } public function offsetExists($offset) { return key_exists($offset, $this->values); } public function offsetGet($offset) { return ($this->offsetExists($offset) ? $this->values[$offset] : null); } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->append($value); return; } if (!$this->offsetExists($offset)) { $cn = get_called_class(); throw new Exception("{$cn} cannot set value at index {$offset}."); } if ($this->validate($value)) { $this->values[$offset] = $this->format($value); } } public function offsetUnset($offset) { if ($this->offsetExists($offset)) { unset($this->values[$offset]); } } public function count() { return count($this->values); } public function current() { return current($this->values); } public function key() { return key($this->values); } public function next() { return next($this->values); } public function rewind() { reset($this->values); } public function valid() { return !is_null(key($this->values)); } public function jsonSerialize() { return $this->toArray(); } public function serialize() { return serialize($this->values); } public function unserialize($data) { $this->values = unserialize($data); } } class IntContainer extends Container { protected function validate($value) { return is_numeric($value); } protected function format($value) { return intval($value); } } $nums = new IntContainer(2, 4, 6, 8); var_dump( $nums->map(function ($num) { return sprintf("[%'10s]",sprintf("0x%10x",$num + 1)); }) ->toArray() );

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.60.0040.01118.43
8.3.50.0130.00916.45
8.3.40.0060.00918.73
8.3.30.0100.00618.67
8.3.20.0030.00521.77
8.3.10.0000.00721.76
8.3.00.0060.00317.93
8.2.180.0060.01218.29
8.2.170.0110.00422.96
8.2.160.0120.00321.14
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0080.00022.25
8.2.120.0000.00926.35
8.2.110.0140.01019.08
8.2.100.0030.01017.79
8.2.90.0090.00018.22
8.2.80.0080.00017.97
8.2.70.0060.00317.75
8.2.60.0080.00017.79
8.2.50.0030.00618.10
8.2.40.0080.00020.52
8.2.30.0080.00019.20
8.2.20.0080.00018.06
8.2.10.0030.00618.12
8.2.00.0040.00417.98
8.1.280.0150.00325.92
8.1.270.0000.00822.11
8.1.260.0000.00726.35
8.1.250.0050.00328.09
8.1.240.0110.00323.91
8.1.230.0070.00420.92
8.1.220.0030.00517.74
8.1.210.0050.00320.10
8.1.200.0060.00317.35
8.1.190.0060.00317.52
8.1.180.0000.00918.10
8.1.170.0080.00018.49
8.1.160.0040.00418.93
8.1.150.0040.00420.23
8.1.140.0040.00419.59
8.1.130.0030.00318.94
8.1.120.0000.00717.48
8.1.110.0030.00617.56
8.1.100.0000.00717.38
8.1.90.0030.00517.50
8.1.80.0000.00817.54
8.1.70.0000.00717.52
8.1.60.0030.00517.65
8.1.50.0040.00417.55
8.1.40.0030.00617.47
8.1.30.0030.00617.54
8.1.20.0040.00417.61
8.1.10.0060.00317.65
8.1.00.0040.00417.60
8.0.300.0080.00020.16
8.0.290.0090.00016.88
8.0.280.0040.00418.54
8.0.270.0000.00717.26
8.0.260.0030.00316.88
8.0.250.0000.00716.90
8.0.240.0000.00916.94
8.0.230.0000.00816.95
8.0.220.0040.00416.95
8.0.210.0040.00416.99
8.0.200.0040.00417.02
8.0.190.0080.00016.97
8.0.180.0000.00717.02
8.0.170.0000.00716.86
8.0.160.0040.00417.00
8.0.150.0050.00216.91
8.0.140.0050.00316.90
8.0.130.0030.00313.34
8.0.120.0000.00716.90
8.0.110.0000.00717.06
8.0.100.0040.00416.81
8.0.90.0000.00716.85
8.0.80.0040.01116.89
8.0.70.0000.00816.79
8.0.60.0040.00416.89
8.0.50.0070.00016.80
8.0.30.0110.00816.99
8.0.20.0080.01117.40
8.0.10.0030.00517.03
8.0.00.0040.01416.88
7.4.330.0060.00015.55
7.4.320.0060.00016.58
7.4.300.0000.00616.67
7.4.290.0060.00316.58
7.4.280.0030.00616.63
7.4.270.0000.00916.54
7.4.260.0030.00313.29
7.4.250.0050.00216.61
7.4.240.0020.00516.63
7.4.230.0070.00016.63
7.4.220.0060.02516.74
7.4.210.0090.01216.57
7.4.200.0080.00016.72
7.4.160.0060.00916.55
7.4.150.0060.01217.40
7.4.140.0140.00317.86
7.4.130.0090.01516.45
7.4.120.0080.01216.63
7.4.110.0170.00016.62
7.4.100.0090.00916.60
7.4.90.0110.00716.44
7.4.80.0140.00619.39
7.4.70.0110.00516.50
7.4.60.0000.01616.57
7.4.50.0030.01016.56
7.4.40.0000.02116.38
7.4.30.0130.00916.38
7.4.10.0100.00715.05
7.4.00.0080.00815.01
7.3.330.0070.00013.14
7.3.320.0060.00013.13
7.3.310.0000.00716.22
7.3.300.0070.00016.32
7.3.290.0120.00316.34
7.3.280.0080.01016.34
7.3.270.0110.00617.40
7.3.260.0130.00716.48
7.3.250.0100.00916.51
7.3.240.0110.00616.48
7.3.230.0070.01116.48
7.3.210.0180.00316.63
7.3.200.0120.01216.50
7.3.190.0110.01116.71
7.3.180.0200.00316.43
7.3.170.0080.00816.48
7.3.160.0070.01016.53
7.3.120.0050.01314.86
7.3.110.0090.01014.76
7.3.100.0050.01015.04
7.3.90.0030.01114.98
7.3.80.0080.00814.97
7.3.70.0060.00514.91
7.3.60.0050.01014.84
7.3.50.0070.00614.91
7.3.40.0030.00814.90
7.3.30.0080.00514.82
7.3.20.0050.00716.57
7.3.10.0050.01016.63
7.3.00.0080.00716.66
7.2.330.0130.00316.48
7.2.320.0000.01716.55
7.2.310.0070.01116.82
7.2.300.0100.00716.81
7.2.290.0000.01616.90
7.2.250.0020.01315.26
7.2.240.0100.00915.18
7.2.230.0030.01415.13
7.2.220.0130.00515.27
7.2.210.0030.00915.27
7.2.200.0050.00615.12
7.2.190.0070.00615.19
7.2.180.0060.00815.26
7.2.170.0030.01115.19
7.2.160.0060.00915.14
7.2.150.0060.00916.82
7.2.140.0060.01016.99
7.2.130.0030.01116.94
7.2.120.0040.01016.93
7.2.110.0030.01016.93
7.2.100.0090.00416.95
7.2.90.0050.01017.03
7.2.80.0100.00716.99
7.2.70.0050.00816.93
7.2.60.0090.00616.93
7.2.50.0090.00616.92
7.2.40.0030.01217.06
7.2.30.0050.00916.96
7.2.20.0050.00916.92
7.2.10.0080.00417.04
7.2.00.0070.00616.88
7.1.330.0040.00915.55
7.1.320.0030.01315.67
7.1.310.0070.00515.92
7.1.300.0020.01315.71
7.1.290.0070.00715.48
7.1.280.0080.00515.79
7.1.270.0050.00815.54
7.1.260.0090.00515.78
7.1.250.0070.00415.72
7.1.240.0060.00715.65
7.1.230.0040.01115.63
7.1.220.0070.00915.81
7.1.210.0020.01015.72
7.1.200.0070.00715.81
7.1.190.0050.00715.68
7.1.180.0080.00415.67
7.1.170.0040.00815.75
7.1.160.0040.00715.79
7.1.150.0040.00815.75
7.1.140.0040.00815.71
7.1.130.0060.00615.79
7.1.120.0030.01015.85
7.1.110.0050.00815.66
7.1.100.0060.00615.69
7.1.90.0040.00815.77
7.1.80.0040.00715.81
7.1.70.0040.00915.98
7.1.60.0160.00820.12
7.1.50.0140.01120.08
7.1.40.0170.00920.01
7.1.30.0210.00919.91
7.1.20.0170.00919.93
7.1.10.0200.00415.44
7.1.00.0170.00515.53
7.0.330.0030.01015.52
7.0.320.0050.00915.25
7.0.310.0030.01215.33
7.0.300.0020.01015.39
7.0.290.0040.00715.24
7.0.280.0040.00815.31
7.0.270.0050.00415.42
7.0.260.0060.00815.29
7.0.250.0060.00715.50
7.0.240.0040.00915.38
7.0.230.0060.00715.51
7.0.220.0080.00615.37
7.0.210.0030.01015.34
7.0.200.0110.00815.30
7.0.190.0120.00615.30
7.0.180.0170.00515.22
7.0.170.0200.00915.14
7.0.160.0180.00815.24
7.0.150.0150.00715.21
7.0.140.0150.00615.12
7.0.130.0160.00915.18
7.0.120.0150.00715.26
7.0.110.0120.00915.26
7.0.100.0180.00615.20
7.0.90.0120.00915.20
7.0.80.0120.00915.25
7.0.70.0270.00715.18
7.0.60.0140.00815.25
7.0.50.0200.00615.24
7.0.40.0160.00613.82
7.0.30.0150.00813.79
7.0.20.0150.00813.69
7.0.10.0140.00813.75
7.0.00.0180.01013.76
5.6.400.0030.01214.37
5.6.390.0000.01414.11
5.6.380.0040.00814.31
5.6.370.0070.01014.59
5.6.360.0040.01114.79
5.6.350.0030.01214.79
5.6.340.0040.01114.75
5.6.330.0000.01614.10
5.6.320.0040.00714.41
5.6.310.0030.00714.36
5.6.300.0090.00614.37
5.6.290.0040.01114.36
5.6.280.0030.01014.42
5.6.270.0030.00914.61
5.6.260.0030.00814.77
5.6.250.0090.00614.66
5.6.240.0000.01614.57
5.6.230.0070.01014.33
5.6.220.0090.00614.48
5.6.210.0060.00614.60
5.6.200.0030.00914.52
5.6.190.0050.00814.68
5.6.180.0130.00014.37
5.6.170.0040.00414.36
5.6.160.0030.00914.29
5.6.150.0050.00514.64
5.6.140.0090.00314.49
5.6.130.0030.01014.19
5.6.120.0070.00714.53
5.6.110.0030.00914.50
5.6.100.0090.00614.36
5.6.90.0090.00614.49
5.6.80.0100.00314.29
5.6.70.0000.01614.25
5.6.60.0000.01714.24
5.6.50.0110.00414.33
5.6.40.0000.01314.66
5.6.30.0030.00914.30
5.6.20.0090.00314.47
5.6.10.0080.00014.10
5.6.00.0080.00414.33

preferences:
35.28 ms | 400 KiB | 5 Q