PHP program, what would this program print?

c2_91

New member
$a = 15;
$b = 4;
$c = 25.0;
$d = 3.0;

echo 4 + $c / 4 * $d, "\n";
echo $a / $d * $a + $c, "\n";
echo $b + $c, $b, $c, "\n";
echo $c = = $d, "\n";
echo $a = = = 15, "\n";
 
In all of these basically remember the order of precedence
1) Parenthesis
2) Exponent
3) Mult/Div
4) Add/Sub
5) Comparisons


ok, so the first expression:
4 + $c / 4 * $d
4 + 25 / 4 * 3
4 + 75 / 4
4 + 18.75
22.75 <-- first line

$a / $d * $a + $c
15 / 3 * 15 + 25
5 * 15 + 25
75 + 25
100 <-- second line

$b + $c, $b, $c
4 + 25, 4, 25
29, 4, 25
the way the program interprets this is no spaces at all:
29425

$c==$d
comparison; is equal to
25==3
which is FALSE (PHP will output 0)
0

triple equals means completely identical; previously we have been able to discount the decimal point but not so anymore.

15===15
this is TRUE.

if it had been $c===25 that would be FALSE.
 
In all of these basically remember the order of precedence
1) Parenthesis
2) Exponent
3) Mult/Div
4) Add/Sub
5) Comparisons


ok, so the first expression:
4 + $c / 4 * $d
4 + 25 / 4 * 3
4 + 75 / 4
4 + 18.75
22.75 <-- first line

$a / $d * $a + $c
15 / 3 * 15 + 25
5 * 15 + 25
75 + 25
100 <-- second line

$b + $c, $b, $c
4 + 25, 4, 25
29, 4, 25
the way the program interprets this is no spaces at all:
29425

$c==$d
comparison; is equal to
25==3
which is FALSE (PHP will output 0)
0

triple equals means completely identical; previously we have been able to discount the decimal point but not so anymore.

15===15
this is TRUE.

if it had been $c===25 that would be FALSE.
 
In all of these basically remember the order of precedence
1) Parenthesis
2) Exponent
3) Mult/Div
4) Add/Sub
5) Comparisons


ok, so the first expression:
4 + $c / 4 * $d
4 + 25 / 4 * 3
4 + 75 / 4
4 + 18.75
22.75 <-- first line

$a / $d * $a + $c
15 / 3 * 15 + 25
5 * 15 + 25
75 + 25
100 <-- second line

$b + $c, $b, $c
4 + 25, 4, 25
29, 4, 25
the way the program interprets this is no spaces at all:
29425

$c==$d
comparison; is equal to
25==3
which is FALSE (PHP will output 0)
0

triple equals means completely identical; previously we have been able to discount the decimal point but not so anymore.

15===15
this is TRUE.

if it had been $c===25 that would be FALSE.
 
In all of these basically remember the order of precedence
1) Parenthesis
2) Exponent
3) Mult/Div
4) Add/Sub
5) Comparisons


ok, so the first expression:
4 + $c / 4 * $d
4 + 25 / 4 * 3
4 + 75 / 4
4 + 18.75
22.75 <-- first line

$a / $d * $a + $c
15 / 3 * 15 + 25
5 * 15 + 25
75 + 25
100 <-- second line

$b + $c, $b, $c
4 + 25, 4, 25
29, 4, 25
the way the program interprets this is no spaces at all:
29425

$c==$d
comparison; is equal to
25==3
which is FALSE (PHP will output 0)
0

triple equals means completely identical; previously we have been able to discount the decimal point but not so anymore.

15===15
this is TRUE.

if it had been $c===25 that would be FALSE.
 
Back
Top