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 git.master_jit, git.master
array(2) { ["area_code"]=> string(5) "01516" ["subscriber_number"]=> string(7) "9999999" } array(2) { ["area_code"]=> string(6) "015180" ["subscriber_number"]=> string(6) "999999" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
30.98 ms | 405 KiB | 5 Q