3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $postcodes = array( 'NE', 'NG', 'PE' ); function matches($needle, $postcodes) { foreach ($postcodes as $postcode) { if ($postcode === substr($needle, 0, strlen($postcode))) { return true; } } return false; } foreach (array('NE1', 'RG', 'PE') as $needle) { printf( "%s %s\n", $needle, matches($needle, $postcodes) ? 'matches' : 'does not match' ); } /* NE1 matches RG does not match PE matches */
Output for 5.2.15 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
NE1 matches RG does not match PE matches
Output for hhvm-3.10.0

Process exited with code 153.