3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = ["categories" => [ [ 'id' => 368, 'name' => 'Aksesuar', 'parentId' => NULL, 'subCategories' => [ [ 'id' => 387, 'name' => 'Saat', 'parentId' => 368, 'subCategories' => [] ], [ 'id' => 394, 'name' => 'Şapka', 'parentId' => 368, 'subCategories' => [] ], [ 'id' => 396, 'name' => 'Takı & Mücevher', 'parentId' => 368, 'subCategories' => [ [ 'id' => 397, 'name' => 'Bileklik', 'parentId' => 396, 'subCategories' => [ [ 'id' => 1238, 'name' => 'Altın Bileklik', 'parentId' => 397, 'subCategories' => [] ] ] ] ] ], ] ] ]]; function recursive(string $needle, array $categories, $id): ?array { foreach ($categories as $cat) { if (array_key_exists($needle, $cat) && $cat[$needle] === $id) { // make sure that if correct category is found, // no subcategories will be included unset($cat['subCategories']); return $cat; } else { $subCat = recursive($needle, $cat['subCategories'], $id); // if the $subCat is not null, it indicates the category // with the correct id, or one of it's parent has been found if ($subCat !== null) { $cat['subCategories'] = $subCat; return $cat; } } } return null; } var_dump(recursive('id', $arr['categories'], 397));

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.5.70.0030.00416.70
8.5.60.0120.00916.91
8.5.50.0050.00416.66
8.5.30.0120.00617.55
8.5.20.0110.00719.41
8.5.10.0120.00616.67
8.5.00.0120.00921.66
8.4.210.0060.00419.59
8.4.180.0100.01319.71
8.4.170.0050.00521.95
8.4.160.0170.01023.93
8.4.150.0070.00716.90
8.4.140.0160.00517.50
8.4.130.0040.00617.82
8.4.120.0050.00320.68
8.4.110.0150.00618.80
8.4.100.0100.00917.69
8.4.90.0130.00820.52
8.4.80.0100.01120.43
8.4.70.0110.00917.87
8.4.60.0100.00918.63
8.4.50.0040.00520.57
8.4.40.0090.00917.55
8.4.30.0100.00920.39
8.4.20.0040.00419.88
8.4.10.0040.00418.80
8.3.300.0200.01018.44
8.3.290.0130.00720.82
8.3.280.0090.01318.45
8.3.270.0140.01016.45
8.3.260.0100.01016.41
8.3.250.0120.00619.10
8.3.240.0100.00917.13
8.3.230.0120.00616.30
8.3.220.0120.00920.69
8.3.210.0120.00616.56
8.3.200.0030.00616.64
8.3.190.0070.01117.21
8.3.180.0100.00918.40
8.3.170.0150.00416.98
8.3.160.0100.01016.39
8.3.150.0060.01220.62
8.3.140.0090.00017.25
8.3.130.0040.00416.81
8.3.120.0160.00318.72
8.3.110.0060.00320.94
8.3.100.0060.00324.06
8.3.90.0090.00626.77
8.3.80.0100.00016.75
8.3.70.0070.00716.58
8.3.60.0120.00918.39
8.3.50.0160.00618.15
8.3.40.0090.00620.42
8.3.30.0110.00418.70
8.3.20.0070.00024.18
8.3.10.0000.00724.66
8.3.00.0070.00026.16
8.2.300.0120.00922.23
8.2.290.0110.00717.26
8.2.280.0050.00418.81
8.2.270.0160.00317.26
8.2.260.0130.00316.68
8.2.250.0040.00418.38
8.2.240.0030.00618.83
8.2.230.0030.00622.58
8.2.220.0100.01037.54
8.2.210.0040.01426.77
8.2.200.0060.00316.63
8.2.190.0120.00916.58
8.2.180.0090.00925.92
8.2.170.0090.00918.91
8.2.160.0070.00722.96
8.2.150.0070.00025.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00420.73
8.2.110.0060.00322.27
8.2.100.0060.00617.72
8.2.90.0060.00317.63
8.2.80.0080.00018.86
8.2.70.0080.00017.63
8.2.60.0030.00617.63
8.2.50.0080.00017.55
8.2.40.0030.00621.11
8.2.30.0070.00018.12
8.2.20.0000.00718.27
8.2.10.0040.00418.76
8.2.00.0000.00719.29
8.1.340.0120.00817.57
8.1.330.0080.01316.14
8.1.320.0050.00316.16
8.1.310.0060.00916.52
8.1.300.0100.01018.06
8.1.290.0060.00318.88
8.1.280.0090.00925.92
8.1.270.0040.00423.99
8.1.260.0050.00326.35
8.1.250.0000.00828.09
8.1.240.0000.00823.97
8.1.230.0080.00319.01
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0040.00417.38
8.1.190.0080.00017.25
8.1.180.0030.00719.01
8.1.170.0000.00818.54
8.1.160.0000.00718.80
8.1.150.0050.00218.57
8.1.140.0040.00417.35
8.1.130.0000.00717.33
8.1.120.0030.00617.43
8.1.110.0000.00817.45
8.1.100.0030.00517.46
8.1.90.0040.00417.39
8.1.80.0000.00917.46
8.1.70.0000.00717.35
8.1.60.0030.00617.46
8.1.50.0000.00817.44
8.1.40.0040.00417.44
8.1.30.0030.00617.71
8.1.20.0000.00917.64
8.1.10.0040.00417.42
8.1.00.0070.00017.48
8.0.300.0040.00419.63
8.0.290.0000.00816.75
8.0.280.0030.00318.43
8.0.270.0000.00718.05
8.0.260.0000.00718.71
8.0.250.0000.00716.82
8.0.240.0030.00317.01
8.0.230.0040.00416.89
8.0.220.0050.00316.88
8.0.210.0030.00316.91
8.0.200.0050.00216.83
8.0.190.0000.00817.00
8.0.180.0040.00416.89
8.0.170.0060.00316.90
8.0.160.0040.00416.88
8.0.150.0080.00016.71
8.0.140.0030.00716.89
8.0.130.0030.00313.31
8.0.120.0000.00816.77
8.0.110.0030.00616.89
8.0.100.0000.00916.92
8.0.90.0060.00316.78
8.0.80.0050.00316.78
8.0.70.0040.00416.93
8.0.60.0030.00516.78
8.0.50.0030.00616.85
8.0.30.0050.00316.89
8.0.20.0040.00416.86
8.0.10.0060.00317.05
8.0.00.0060.00317.07
7.4.330.0060.00015.55
7.4.320.0040.00416.51
7.4.300.0000.00716.41
7.4.290.0080.00016.39
7.4.280.0040.00416.60
7.4.270.0030.00316.52
7.4.260.0030.00313.33
7.4.250.0030.00316.63
7.4.240.0000.00816.58
7.4.230.0040.00416.61
7.4.220.0000.00716.59
7.4.210.0040.00416.46
7.4.200.0080.00016.51
7.4.190.0000.00716.68
7.4.180.0020.00516.42
7.4.160.0050.00316.57
7.4.150.0000.00816.41
7.4.140.0000.00716.46
7.4.130.0000.00816.32
7.4.120.0040.00416.40
7.4.110.0040.00416.45
7.4.100.0000.00716.46
7.4.90.0060.00316.44
7.4.80.0000.00816.55
7.4.70.0040.00416.52
7.4.60.0070.00016.36
7.4.50.0050.00316.46
7.4.40.0040.00416.26
7.4.30.0050.00216.41
7.4.20.0040.00416.43
7.4.10.0070.00016.54
7.4.00.0080.00016.43
7.3.330.0040.00416.29
7.3.320.0030.00313.20
7.3.310.0000.00816.41
7.3.300.0040.00416.41
7.3.290.0000.00716.37
7.3.280.0000.01016.23
7.3.270.0070.00016.17
7.3.260.0000.00716.33
7.3.250.0040.00416.26
7.3.240.0040.00416.41
7.3.230.0040.00416.40
7.3.220.0030.00316.32
7.3.210.0040.00416.29
7.3.200.0070.00016.30
7.3.190.0030.00316.33
7.3.180.0040.00416.32
7.3.170.0000.00816.16
7.3.160.0070.00016.34
7.3.150.0000.00816.29
7.3.140.0050.00216.14
7.3.130.0030.00516.36
7.3.120.0050.00216.36
7.3.110.0000.00716.25
7.3.100.0040.00416.24
7.3.90.0030.00316.57
7.3.80.0000.00716.36
7.3.70.0000.00716.47
7.3.60.0030.00316.55
7.3.50.0020.00516.37
7.3.40.0000.00716.52
7.3.30.0000.00716.37
7.3.20.0040.00418.23
7.3.10.0050.00318.15
7.3.00.0040.00418.28

preferences:
52.9 ms | 1477 KiB | 5 Q