Operators And Expressions In Php - Study Mode

[#76] What will be the output of the following PHP code ? <?php $i = 10
$j = 0
if ( $i || ( $j = $i + 10 )) { echo "true"
} echo $j
?>
Correct Answer

(B) true0

Explanation

Solution: In if condition when the first case is 1 and is an || operation then the second command is not executed.

[#77] What will be the output of the following PHP code ? <?php $i = 1
if ( $i ++ && ( $i == 1 )) printf( "Yesn$i" )
else printf( "Non$i" )
?>
Correct Answer

(A) No 2

Explanation

Solution: The first condition returns true and increments but the second condition is false.

[#78] What will be the output of the following PHP code ? <?php $a = 1
$b = 3
$d = $a ++ + ++ $b
echo $d
?>
Correct Answer

(A) 5

Explanation

Solution: Post increment of a is done after expression evaluation.

[#79] What will be the output of the following PHP code ? <?php $a = 1
$b = 1
$d = 1
print ++ $a + ++ $a + $a ++
print $a ++ + ++ $b
print ++ $d + $d ++ + $a ++
?>
Correct Answer

(A) 869

Explanation

Solution: Follow the order of post and pre increments.

[#80] What will be the output of the following PHP code ? <?php $a = 10
$b = 10
if ( $a = 5 ) $b --
print $a
print $b --
?>
Correct Answer

(B) 59

Explanation

Solution: a is set to 5 in the if condition and b is postdecremented in the print statement.