3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Arr { public static function collapse($array, $prefix = '') { $output = []; foreach($array as $key => $value) { if (Assert::that($value)->array()->result()) { static::merge($output, static::collapse($value, $prefix . $key . '.')); } else { } } return $output; } public static function merge(...$arrays) { Assert::that($arrays)->items('array')->error(); $output = []; foreach($arrays as $array) { $output = array_merge($output, $array); } return $output; } public static function join($glue = '', $array = []) { return implode($glue, $array); } } class Funct { public static function getCaller($offset = 0, $full = false) { return static::nameFromBacktrace(debug_backtrace()[2 + $offset], $full); } public static function nameFromBacktrace($backtrace, $full = false) { if($full) { if(!array_key_exists('type', $backtrace)) return $backtrace['function']; if($backtrace['type'] === '::') { return $backtrace['class'] . '::' . $backtrace['function']; } elseif($backtrace['type'] === '->') { return [$backtrace['class'], $backtrace['function']]; } } return $backtrace['function']; } } class Assert { protected $variable; protected $invalidated = false; protected $invalidatedBy = []; protected function __construct($variable) { $this->variable = $variable; } public static function that($variable) { return new static($variable); } public function string() { return $this->check('is_string'); } public function array() { return $this->check('is_array'); } public function object() { return $this->check('is_object'); } public function boolean() { return $this->check('is_bool'); } public function callable() { return $this->check('is_callable'); } public function integer() { return $this->check('is_int'); } public function null() { return $this->check('is_null'); } public function float() { return $this->check('is_float'); } public function double() { return $this->check('is_double'); } public function resource() { return $this->check('is_resource'); } public function type($type) { return $this->check('is_a', $type); } public function items($type) { return $this->checkAll('is_a', $type); } protected function check(callable $function, ...$parameters) { array_unshift($parameters, $this->variable); if(!call_user_func_array($function, $parameters)) $this->invalidate(); return $this; } protected function checkAll(callable $function, ...$parameters) { foreach($this->variable as $value) { array_unshift($parameters, $value); if(!call_user_func_array($function, $parameters)) $this->invalidate(); break; } return $this; } public function result() { return !$this->invalidated; } public function error() { if(!$this->result()) throw new \AssertionError("The assertion failed at: " . Arr::join(', ', $this->invalidatedBy)); } protected function invalidate($by = null) { $this->invalidated = true; $this->invalidatedBy[] = Funct::getCaller(1); var_dump($this->invalidated, $this->invalidatedBy); } } Assert::that(true)->string(); Assert::that(1)->string(); Assert::that([])->string();

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.01816.75
8.3.50.0060.01216.25
8.3.40.0040.01118.84
8.3.30.0110.01118.66
8.3.20.0040.00420.33
8.3.10.0050.00321.86
8.3.00.0040.00423.65
8.2.180.0090.00916.50
8.2.170.0080.00822.96
8.2.160.0090.00920.48
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0090.00019.95
8.2.120.0070.00026.35
8.2.110.0050.00522.21
8.2.100.0120.00018.05
8.2.90.0030.00519.21
8.2.80.0030.00517.97
8.2.70.0000.00917.63
8.2.60.0040.00418.04
8.2.50.0040.00418.07
8.2.40.0050.00322.14
8.2.30.0080.00019.59
8.2.20.0070.00017.66
8.2.10.0050.00318.26
8.2.00.0000.00718.06
8.1.280.0110.01125.92
8.1.270.0030.00623.84
8.1.260.0080.00428.09
8.1.250.0040.00428.09
8.1.240.0060.00322.06
8.1.230.0040.00718.97
8.1.220.0040.00417.74
8.1.210.0030.00518.77
8.1.200.0060.00317.10
8.1.190.0060.00317.23
8.1.180.0090.00018.10
8.1.170.0000.00818.57
8.1.160.0050.00220.80
8.1.150.0040.00418.85
8.1.140.0040.00419.49
8.1.130.0030.00317.74
8.1.120.0040.00417.50
8.1.110.0080.00317.51
8.1.100.0040.00417.46
8.1.90.0060.00317.50
8.1.80.0000.00817.39
8.1.70.0040.00417.51
8.1.60.0040.00417.50
8.1.50.0060.00317.57
8.1.40.0030.00517.61
8.1.30.0060.00317.73
8.1.20.0030.00517.64
8.1.10.0000.00717.57
8.1.00.0030.00617.56
8.0.300.0080.00018.77
8.0.290.0000.00716.75
8.0.280.0070.00018.48
8.0.270.0040.00417.16
8.0.260.0060.00017.21
8.0.250.0030.00317.06
8.0.240.0000.00617.00
8.0.230.0030.00316.94
8.0.220.0040.00416.91
8.0.210.0000.00717.03
8.0.200.0050.00317.05
8.0.190.0000.00816.89
8.0.180.0040.00417.04
8.0.170.0030.00617.02
8.0.160.0040.00416.89
8.0.150.0000.00816.83
8.0.140.0040.00416.95
8.0.130.0070.00013.48
8.0.120.0040.00416.94
8.0.110.0050.00316.92
8.0.100.0040.00417.00
8.0.90.0000.00816.92
8.0.80.0120.00316.90
8.0.70.0050.00316.94
8.0.60.0070.00017.03
8.0.50.0050.00316.92
8.0.30.0130.00717.05
8.0.20.0130.00717.41
8.0.10.0070.00017.05
8.0.00.0070.01216.83
7.4.330.0050.00016.67
7.4.320.0060.00016.49
7.4.300.0050.00216.61
7.4.290.0050.00316.55
7.4.280.0060.00316.59
7.4.270.0000.00716.62
7.4.260.0000.00716.55
7.4.250.0040.00416.43
7.4.240.0020.00616.59
7.4.230.0000.00716.45
7.4.220.0110.01116.65
7.4.210.0040.01116.66
7.4.200.0000.00716.75
7.4.160.0080.00816.43
7.4.150.0040.01917.40
7.4.140.0090.01117.86
7.4.130.0130.00816.49
7.4.120.0110.00816.62
7.4.110.0180.02916.56
7.4.100.0100.00916.55
7.4.90.0100.00716.53
7.4.80.0070.01019.39
7.4.70.0190.00316.43
7.4.60.0070.01016.57
7.4.50.0040.01516.64
7.4.40.0100.00716.55
7.4.30.0030.01416.68
7.4.00.0060.00915.03
7.3.330.0000.00513.41
7.3.320.0060.00313.48
7.3.310.0020.00516.46
7.3.300.0030.00316.41
7.3.290.0110.00716.39
7.3.280.0100.00716.38
7.3.270.0080.00917.40
7.3.260.0000.01816.48
7.3.250.0110.00916.40
7.3.240.0120.00916.39
7.3.230.0090.00916.55
7.3.210.0160.00716.36
7.3.200.0100.01019.39
7.3.190.0070.01416.46
7.3.180.0110.00516.57
7.3.170.0130.00316.33
7.3.160.0080.00816.46
7.2.330.0150.00316.79
7.2.320.0070.01116.81
7.2.310.0100.00716.59
7.2.300.0000.02116.79
7.2.290.0170.00316.64
7.2.60.0040.01117.02
7.2.00.0000.01119.32
7.1.200.0060.00615.59
7.1.100.0040.00718.25
7.1.70.0030.01117.27
7.1.60.0170.00719.27
7.1.50.0100.01017.02
7.1.00.0030.07722.30
7.0.200.0060.00316.86
7.0.100.0430.04319.95
7.0.90.0100.04320.00
7.0.80.0100.07020.02
7.0.70.0070.07319.97
7.0.60.0100.08019.98
7.0.50.0100.08020.38
7.0.40.0130.08020.09
7.0.30.0070.06720.13
7.0.20.0030.07320.13
7.0.10.0070.08319.99
7.0.00.0100.06720.12
5.6.250.0030.08020.65
5.6.240.0100.07720.78
5.6.230.0070.09020.74
5.6.220.0070.04720.51
5.6.210.0070.03720.63
5.6.200.0130.08021.09
5.6.190.0070.08021.16
5.6.180.0070.08021.05
5.6.170.0170.06721.16
5.6.160.0070.08721.07
5.6.150.0070.07321.16
5.6.140.0070.05321.07
5.6.130.0100.05721.02
5.6.120.0030.05321.19
5.6.110.0030.05721.10
5.6.100.0030.08321.01
5.6.90.0030.04721.11
5.6.80.0100.06020.54
5.6.70.0130.07020.48
5.6.60.0100.03720.46
5.6.50.0170.09020.58
5.6.40.0130.07320.42
5.6.30.0100.06020.32
5.6.20.0100.04320.45
5.6.10.0070.08320.45
5.6.00.0130.06720.40
5.5.380.0030.05020.38
5.5.370.0130.03320.36
5.5.360.0130.04720.44
5.5.350.0230.06320.38
5.5.340.0030.06020.77
5.5.330.0030.06720.92
5.5.320.0130.06720.91
5.5.310.0100.06720.78
5.5.300.0170.07320.84
5.5.290.0170.08320.84
5.5.280.0100.07320.91
5.5.270.0070.07720.92
5.5.260.0100.06020.87
5.5.250.0100.06720.45
5.5.240.0130.07320.30
5.5.230.0030.06320.02
5.5.220.0130.08020.28
5.5.210.0130.07019.98
5.5.200.0070.08020.18
5.5.190.0130.06320.24
5.5.180.0030.05320.24
5.5.160.0100.06719.98
5.5.150.0130.07720.18
5.5.140.0100.08320.18
5.5.130.0030.07320.13
5.5.120.0070.06320.13
5.5.110.0070.04720.26
5.5.100.0070.05020.16
5.5.90.0130.07019.93
5.5.80.0070.06019.98
5.5.70.0070.04720.07
5.5.60.0030.06320.06
5.5.50.0170.05720.14
5.5.40.0030.04720.08
5.5.30.0030.04720.08
5.5.20.0070.07719.94
5.5.10.0100.07020.14
5.5.00.0100.07320.00

preferences:
59.02 ms | 400 KiB | 5 Q