Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$email = 'admin@site.ru';
if (strpos($email, 'admin')) {
echo 'found';
} else {
echo 'missing';
}
echo ' ', str_contains($email, 'admin') ? 'yes' : 'no', "\n";missing yes
- Expecting
if (strpos(...))to catch every match: a match at the start gives the position0, which is falsy, so theelsebranch runs. - Expecting
str_containsto share that trap: it returns onlytrueorfalse, so a match at the start is stilltrue.
- How would you rewrite the
ifso that it works correctly withstrpos? - What does
strpos($email, 'root')return, and how doesvar_dumpshow it?