Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
<?php
$ids = ['10', 7, '1e1'];
var_dump(in_array(10, $ids));
var_dump(in_array('7', $ids, true));
var_dump(array_search(7, $ids));bool(true) bool(false) int(1)
- Expecting
in_arrayto compare strictly: by default it uses==, soin_array(10, ['10'])is true; passtrueas the third argument to compare with===. - Expecting
array_searchto returntruelikein_array: it returns the key of the first match, here1, andfalseonly when nothing matches.
- Why can a missing third argument let a wrong value pass an
in_arraywhitelist check? - What does
array_search('7', $ids, true)return for this array?