3v4l.org

run code in 500+ PHP versions simultaneously
<?php function array_search_range( mixed $needle, array $haystack, int $offset = 0, ?int $length = null, bool $strict = false, ): int|string|false { if ( $offset < 0 ) { $offset = count($haystack) + $offset; } if ( $length < 0 ) { $length = count($haystack) + $length - $offset; } $currentOffset = -1; foreach ( $haystack as $key => $value ) { $currentOffset++; if ( $currentOffset < $offset ) { continue; } if ( $length !== null && $currentOffset >= $offset + $length ) { break; } if ( ( $strict && $value === $needle ) || ( ! $strict && $value == $needle ) ) { return $key; } } return false; } $items = ['zero', 'one', 'two', 'target', 'four', 'target']; $key = array_search_range('target', $items, 2, 3, true); var_dump($key); // int(3) $items = ['zero', 'one', 'two', 'target', 'four', 'target']; $key = array_search_range('target', $items, 4, null, true); var_dump($key); // int(5) $items = ['zero', 'one', 'two', 'target', 'four', 'target']; $key = array_search_range('target', $items, 1, 2, true); var_dump($key); // bool(false) $items = ['zero', 'one', 'two', 'target', 'four', 'target']; $key = array_search_range('target', $items, 1, -3, true); var_dump($key); // bool(false)

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.90.0240.00517.64
8.5.80.0180.00717.58
8.5.70.0220.00417.66
8.5.60.0180.00517.64
8.5.50.0160.00317.55
8.5.40.0200.00417.54
8.5.30.0160.00517.57
8.5.20.0180.00617.44
8.5.10.0130.00717.52
8.5.00.0070.00417.29
8.4.240.0130.00520.44
8.4.230.0110.00520.16
8.4.220.0100.00520.40
8.4.210.0120.00820.45
8.4.200.0120.00320.46
8.4.190.0120.00420.46
8.4.180.0150.00320.58
8.4.170.0120.00320.47
8.4.160.0110.00420.44
8.4.150.0120.00820.54
8.4.140.0100.00418.63
8.4.130.0140.00518.53
8.4.120.0110.00818.63
8.4.110.0170.00818.70
8.4.100.0180.00918.63
8.4.90.0180.01118.63
8.4.80.0200.00918.68
8.4.70.0160.00618.61
8.4.60.0150.00518.66
8.4.50.0100.00418.66
8.4.40.0160.00418.58
8.4.30.0130.00818.53
8.4.20.0170.00318.42
8.4.10.0160.00618.47
8.3.330.0160.00619.22
8.3.320.0120.00819.19
8.3.310.0140.00519.19
8.3.300.0120.00719.21
8.3.290.0120.00719.13
8.3.280.0130.00719.23
8.3.270.0120.00217.55
8.3.260.0130.00717.54
8.3.250.0140.00617.48
8.3.240.0140.00617.50
8.3.230.0140.00617.55
8.3.220.0150.00617.38
8.3.210.0150.00617.58
8.3.200.0150.00417.48
8.3.190.0090.01017.52
8.3.180.0140.00617.61
8.3.170.0120.00717.66
8.3.160.0140.00517.53
8.3.150.0140.00617.53
8.3.140.0140.00517.53
8.3.130.0130.00617.54
8.3.120.0130.00417.45
8.3.110.0130.00517.50
8.3.100.0130.00817.66
8.3.90.0150.00617.57
8.3.80.0140.00517.54
8.3.70.0160.00517.48
8.3.60.0130.00717.43
8.3.50.0140.00717.61
8.3.40.0150.00618.74
8.3.30.0150.00318.74
8.3.20.0130.00918.87
8.3.10.0130.00818.88
8.3.00.0130.00618.83
8.2.330.0210.00718.76
8.2.320.0120.00718.94
8.2.310.0120.00818.93

preferences:
48.46 ms | 778 KiB | 5 Q