3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php error_reporting(E_ALL); function containsString($str, $cont = array()) { $arr = ( ! is_array($cont)) ? array($cont) : $cont; // turn the string into an array foreach ($arr as $char) { if (strstr($str, $char)) { return true; } } return false; } function containsString_mlocati($str, $cont = array()) { $arr = is_array($cont) ? $cont : array($cont); foreach($arr as $item) { if(strstr($str, $item) !== false) { return true; } } return false; } $str = 'Number of items: 0'; echo "Usually works:\n"; $cont = 'not-existing'; echo 'Your-1: ', var_dump(containsString($str, $cont)); echo 'Mine-1: ', var_dump(containsString_mlocati($str, $cont)); $cont = 'items'; echo 'Your-2: ', var_dump(containsString($str, $cont)); echo 'Mine-2: ', var_dump(containsString_mlocati($str, $cont)); echo "\n\n"; echo "**BUT:\n"; $cont = '0'; echo 'Your-3: ', var_dump(containsString($str, $cont)); echo 'Mine-3: ', var_dump(containsString_mlocati($str, $cont));
Output for 4.3.0 - 7.1.0
Usually works: Your-1: bool(false) Mine-1: bool(false) Your-2: bool(true) Mine-2: bool(true) **BUT: Your-3: bool(false) Mine-3: bool(true)