0
if
文に2つのpreg_matchがあり、いずれかが真である場合は、両方ともprint_rしたいです。しかし、何らかの理由で、最初のpreg_match
だけが、同じパターンを持っていても毎回一致しています。なぜこうなった?if文のpreg_matchesの両方を一致させる
<?php
$string = "how much is it?";
if (preg_match("~\b(how (much|many))\b~", $string, $match1) || preg_match("~\b(how (much|many))\b~", $string, $match2)) {
print_r($match1);
print_r($match2);
}
?>
結果:
Array ([0] => how much [1] => how much [2] => much)
期待される結果:
Array ([0] => how much [1] => how much [2] => much)
Array ([0] => how much [1] => how much [2] => much)
http://php.net/manual/en/language.operators.logical.php – axiac