Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
<?php
$age = filter_var('42abc', FILTER_VALIDATE_INT);
$email = filter_var('ann@site.ru', FILTER_VALIDATE_EMAIL);
$sort = 'price';
$ok = in_array($sort, ['name', 'price'], true);
var_dump($age, $email, $ok);bool(false) string(11) "ann@site.ru" bool(true)
- Expecting
filter_var('42abc', FILTER_VALIDATE_INT)to give42, as(int)does: the filter checks the whole string, and any letter makes it returnfalse. - Expecting
FILTER_VALIDATE_EMAILto returntruefor a valid address:filter_varreturns the checked value itself, here the string'ann@site.ru'.
- Why must the result of
filter_varbe compared with=== falseand not checked with!? - What does
in_array('1', [1, 2])give without the third argument, and why is it risky?