3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Returns the index of the first match or -1 if not found. */ function arraySearch(array $array, string $search): int { foreach ($array as $key => $value) { if (strpos($value, $search) !== false) { return $key; } } return -1; } $unique_domains = [ 'www.crownworldwide.com', 'www.acquisition.gov', 'www.hemisphere-freight.com', 'www.businessinsider.com', 'www.oceansidelogistics.com', 'mixjet.aero', 'www.airindiaexpress.in', 'rlglobal.com', 'www.metroshipping.co.uk', 'www.flexport.com' ]; $position = arraySearch($unique_domains, 'flexport.com'); echo $position; // 9
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
9

preferences:
123.51 ms | 406 KiB | 5 Q