Этот код кажется мне довольно простым и логичным, я должен быть уставшим, потому что он не выполняет то, что я ожидаю ..
//look for any letter, number or underscore
$regexTags = "/[a-z0-9_]/i";
//needlessly large string..
$string = "111 222 333 444 555 666 777";
preg_match_all($regexTags, $string, $regexMatches);
print_r($regexMatches);
//$regexMatches spits out [0] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 2 [4] => 2 [5] => 2 [6] => 3 [7] => 3 [8] => 3 [9] => 4 [10] => 4 [11] => 4 [12] => 5 [13] => 5 [14] => 5 [15] => 6 [16] => 6 [17] => 6 [18] => 7 [19] => 7 [20] => 7))
//as expected.
//Count how many variables are in the array
$matchCount = count($regexMatches);
if ($matchCount < 5){
echo "less than 5";
}
Почему «меньше 5» все еще печатается, хотя в массиве $ regexMatches совершенно ясно, что есть 20 значений? Что я делаю не так?