Operators And Expressions In Php - Study Mode

[#41] What will be the output of the following PHP code ? <?php $x = 0

function fun () { echo $GLOBALS[ 'x' ]

$GLOBALS[ 'x' ]++

} fun ()

fun ()

fun ()

?>
Correct Answer

(B) 012

Explanation

Solution: Since, we are using $GLOBALS[‘x’], the question is similar to question 7.

[#42] What will be the output of the following PHP code ? <?php $one = "one"
$two = "two"
print( "$one$two" )
?>
Correct Answer

(A) onetwo

Explanation

Solution: This is same as the echo statement.

[#43] What will be the output of the following PHP code ? <?php $one = "one"
$two = "two"
print( $one == $two )
?>
Correct Answer

(C) nothing

Explanation

Solution: Since we are equating two unequal strings we do not get any output.

[#44] What will be the output of the following PHP code ? <?php $one = "one"
$two = "one"
print( $one == $two )
?>
Correct Answer

(C) 1

Explanation

Solution: Since both the strings are equal the result 1 is printed on the screen.

[#45] What will be the output of the following PHP code ? <?php print( "this" . "was" . "a" . "bad" . "idea" )
?>
Correct Answer

(A) thiswasabadidea

Explanation

Solution: You can use the dot operator like in echo but you can not use the comma operator to do the same.