3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); final class PathAsKeyDecorator implements \Iterator { private RecursiveIteratorIterator $inner; public function __construct(RecursiveIteratorIterator $inner) { $this->inner = $inner; } public function current() { return $this->inner->current(); } public function next(): void { $this->inner->next(); } public function key() { $path = []; for ($i = 0, $depth = $this->inner->getDepth(); $i <= $depth; $i++) { $path[] = $this->inner->getSubIterator($i)->key(); } return $path; } public function valid(): bool { return $this->inner->valid(); } public function rewind(): void { $this->inner->rewind(); } } $input = [ 'steve' => [ 'id' => [ '#text' => 1, ], ], 'albert' => [ 'id' => [ '#text' => 2, ], ], 'john' => [ 'profil' => [ 'id' => [ '#text' => 3, ], ], ], ]; // this is the filter function that should be customized given your requirements // or create a factory function which produces these types of filter functions $filter = static function ($current, array $path): bool { // with help from the PathAsKeyDecorator // we can decide on the path to the current value return ['id', '#text'] === array_slice($path, -2) // and the current value && 2 === $current; }; // configure the iterator $it = new CallbackFilterIterator( new PathAsKeyDecorator(new RecursiveIteratorIterator(new RecursiveArrayIterator($input))), $filter, ); // traverse the iterator foreach ($it as $path => $val) { print_r([ 'path' => $path, 'val' => $val ]); }

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.4.120.0050.00525.77
8.4.110.0100.01022.41
8.4.100.0170.00417.79
8.4.90.0130.00720.36
8.4.80.0060.00318.85
8.4.70.0110.01018.95
8.4.60.0100.01018.94
8.4.50.0130.00720.53
8.4.40.0050.00517.81
8.4.30.0160.00018.82
8.4.20.0070.01318.15
8.4.10.0070.01419.63
8.3.250.0080.01119.22
8.3.240.0110.00816.97
8.3.230.0050.00616.69
8.3.220.0160.00419.16
8.3.210.0140.00516.96
8.3.200.0040.00516.55
8.3.190.0100.00717.13
8.3.180.0090.01116.81
8.3.170.0070.01117.20
8.3.160.0090.00918.58
8.3.150.0120.00618.31
8.3.140.0060.00316.84
8.3.130.0090.00618.73
8.3.120.0110.00820.58
8.3.110.0020.00516.74
8.3.100.0070.01016.66
8.3.90.0000.00826.77
8.3.80.0030.00716.73
8.3.70.0090.00616.88
8.3.60.0140.00716.75
8.3.50.0100.01024.57
8.3.40.0130.00618.97
8.3.30.0040.01118.88
8.3.20.0090.00024.18
8.3.10.0050.00324.66
8.3.00.0100.00026.16
8.2.290.0140.00520.68
8.2.280.0080.00120.55
8.2.270.0160.00317.29
8.2.260.0080.00016.85
8.2.250.0100.00518.57
8.2.240.0040.00417.30
8.2.230.0030.00620.94
8.2.220.0050.00324.06
8.2.210.0080.00026.77
8.2.200.0090.00016.88
8.2.190.0100.00716.58
8.2.180.0040.01425.92
8.2.170.0090.00619.07
8.2.160.0110.00422.96
8.2.150.0000.00725.66
8.2.140.0000.00824.66
8.2.130.0090.00026.16
8.2.120.0030.00526.35
8.2.110.0050.00520.95
8.2.100.0070.00417.72
8.2.90.0040.00418.28
8.2.80.0060.00319.34
8.2.70.0080.00017.75
8.2.60.0000.00817.63
8.2.50.0060.00318.10
8.2.40.0030.00519.47
8.2.30.0050.00219.37
8.2.20.0000.01018.01
8.2.10.0070.00019.30
8.2.00.0080.00319.38
8.1.330.0130.00721.92
8.1.320.0100.00918.01
8.1.310.0090.00918.09
8.1.300.0060.00317.97
8.1.290.0070.00430.84
8.1.280.0090.01225.92
8.1.270.0050.00523.99
8.1.260.0040.00428.09
8.1.250.0080.00028.09
8.1.240.0050.00522.46
8.1.230.0110.00020.89
8.1.220.0000.00817.74
8.1.210.0040.00419.03
8.1.200.0060.00317.35
8.1.190.0000.00817.23
8.1.180.0030.00518.10
8.1.170.0080.00018.68
8.1.160.0110.00019.03
8.1.150.0040.00418.87
8.1.140.0040.00418.81
8.1.130.0040.00417.34
8.1.120.0050.00317.48
8.1.110.0000.00817.48
8.1.100.0000.00817.45
8.1.90.0000.00717.44
8.1.80.0030.00517.50
8.1.70.0000.00717.36
8.1.60.0040.00417.46
8.1.50.0080.00017.52
8.1.40.0030.00517.55
8.1.30.0030.00617.60
8.1.20.0000.00817.66
8.1.10.0000.00717.59
8.1.00.0040.00417.54
8.0.300.0040.00420.23
8.0.290.0050.00516.75
8.0.280.0070.00018.45
8.0.270.0070.00016.77
8.0.260.0090.00016.89
8.0.250.0070.00016.97
8.0.240.0000.00817.07
8.0.230.0000.00716.91
8.0.220.0070.00016.94
8.0.210.0000.00716.96
8.0.200.0000.00716.94
8.0.190.0040.00417.02
8.0.180.0040.00416.86
8.0.170.0000.00916.93
8.0.160.0040.00416.93
8.0.150.0060.00316.93
8.0.140.0030.00616.84
8.0.130.0000.00713.37
8.0.120.0080.00016.94
8.0.110.0000.00716.86
8.0.100.0000.00716.81
8.0.90.0040.00416.80
8.0.80.0120.00316.90
8.0.70.0020.00516.82
8.0.60.0080.00016.80
8.0.50.0020.00516.94
8.0.30.0100.00517.22
8.0.20.0080.01317.14
8.0.10.0040.00417.05
8.0.00.0110.01116.66
7.4.330.0000.00515.55
7.4.320.0070.00016.53
7.4.300.0080.00016.44
7.4.290.0000.00716.60
7.4.280.0040.00416.52
7.4.270.0070.00016.54
7.4.260.0000.01016.61
7.4.250.0070.00016.60
7.4.240.0040.00416.65
7.4.230.0000.00816.41
7.4.220.0020.00516.58
7.4.210.0070.00916.62
7.4.200.0040.00416.59
7.4.130.0110.00916.60
7.4.120.0110.00616.43
7.4.110.0120.00916.50
7.4.100.0000.01616.57
7.4.90.0100.01416.38
7.4.80.0130.00616.50
7.4.70.0120.00816.30
7.4.60.0060.01316.38
7.4.50.0190.00316.64
7.4.40.0130.01016.29
7.4.30.0030.01716.24
7.4.20.0030.01416.07
7.4.10.0170.00316.42
7.4.00.0120.00616.30
7.3.330.0090.00016.13
7.3.320.0000.00613.08
7.3.310.0030.00316.04
7.3.300.0060.00016.22
7.3.290.0100.00716.20
7.3.260.0090.00916.07
7.3.230.0100.00716.33
7.3.210.0100.00616.18
7.3.200.0100.00716.12
7.3.190.0080.01116.27
7.3.180.0070.01016.30
7.3.170.0160.00716.20
7.3.160.0030.01716.15
7.3.150.0090.00916.21
7.3.140.0040.01315.94
7.3.130.0060.01216.16
7.3.120.0100.01016.13
7.3.110.0100.00716.15
7.3.100.0090.01516.07
7.3.90.0080.00816.13
7.3.80.0070.01016.13
7.3.70.0070.01016.20
7.3.60.0090.01316.00
7.3.50.0100.00716.20
7.3.40.0120.01216.00
7.3.30.0080.01516.20
7.3.20.0060.01216.04
7.3.10.0190.00816.30
7.3.00.0070.01316.21
7.2.330.0070.01016.51
7.2.320.0150.00416.30
7.2.310.0130.01016.46
7.2.300.0090.01516.36
7.2.290.0120.00616.21
7.2.280.0130.00616.43
7.2.270.0150.00916.36
7.2.260.0180.00016.45
7.2.250.0070.01016.50
7.2.240.0070.01116.23
7.2.230.0130.00616.27
7.2.220.0060.01316.08
7.2.210.0000.01816.54
7.2.200.0040.01516.36
7.2.190.0090.00916.50
7.2.180.0060.01216.43
7.2.170.0150.00316.26
7.2.160.0060.01216.50
7.2.150.0110.00816.39
7.2.140.0090.01216.45
7.2.130.0040.01516.50
7.2.120.0090.00916.25
7.2.110.0140.00616.48
7.2.100.0080.01116.45
7.2.90.0130.01016.37
7.2.80.0140.01016.09
7.2.70.0110.00916.07
7.2.60.0150.00316.39
7.2.50.0060.01216.48
7.2.40.0100.01016.12
7.2.30.0180.00016.40
7.2.20.0150.00316.34
7.2.10.0210.00416.52
7.2.00.0120.00616.34

preferences:
33.29 ms | 403 KiB | 5 Q