Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
<?php
$a = 10 / 5;
$b = 7 / 2;
$c = (int) '12 apples';
var_dump($a, $b, $c);int(2) float(3.5) int(12)
- Expecting
float(2), as if/always gave afloat: PHP's/on twoints returns anintwhen the division is exact and afloatonly when a fraction is left. - Expecting
(int) '12 apples'to give 0 or an error: a cast reads the digits at the start of the string, drops the rest and gives 12 without any message.
- What do
var_dump(10 / 4)andvar_dump(intdiv(10, 4))print? - What happens with
'12 apples' + 1instead of the cast, and with'apples' + 1?