Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
<?php
var_dump((bool) '0');
var_dump((bool) '0.0');
var_dump((bool) []);
var_dump((bool) ' ');bool(false) bool(true) bool(false) bool(true)
- Expecting
'0.0'to be false like'0': the cast toboollooks at the text, and only''and'0'are false strings, so'0.0'is true. - Expecting
[]to be true, as in JavaScript: in PHP an empty array is false, and only an array with at least one element is true.
- What does
var_dump((bool) '00');print, and why? - Why can
if ($input)reject a valid form value such as'0'?