3v4l.org

run code in 300+ PHP versions simultaneously
<?php $area_codes = array( '015019', '015020', '01511', '01512', '01514', '01515', '01516', '01517', '015180', '015181', '015182', '015183', '015184', '015185', ); // Build an associative array $area_lookup = []; foreach($area_codes as $code) $area_lookup[$code] = 1; function splitNumber(array $area_lookup, string $telephone_number): array { for($len=4;$len<=6;$len++) { $prefix = substr($telephone_number, 0, $len); if(isset($area_lookup[$prefix])) return ['area_code' => $prefix, 'subscriber_number' => substr($telephone_number, $len)]; } throw new Exception('Invalid number'); } $res1 = splitNumber($area_lookup, '015169999999'); $res2 = splitNumber($area_lookup, '015180999999'); var_dump($res1, $res2);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
array(2) { ["area_code"]=> string(5) "01516" ["subscriber_number"]=> string(7) "9999999" } array(2) { ["area_code"]=> string(6) "015180" ["subscriber_number"]=> string(6) "999999" }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
78.57 ms | 407 KiB | 5 Q