PHP Operators
- What will be the output of the following PHP code ?
<?php
$t = 5;
if ($t-- == ++$t)
{
echo $t;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
First $t = 5 is compared to and then decremented, then incremented and compared to $t = 5.
- What will be the output of the following PHP code ?
<?php
$s = 4;
$t = 8;
$s *= $t /= $s;
echo $s, $t;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Expression is evaluated from right to left.
- What will be the output of the following PHP code ?
<?php
$p = 5;
$q = 6;
if (++$p == $q++)
{
echo "true ", $q, $p;
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
p is preincremented and q is post incremented thus both are 6 in the if condition, later q is increment.
- What will be the output of the following PHP code ?
<?php
$str1 = "Hello ";
$str2 = "Interview ";
$str3 = "Mania ";
$str1 .= $str2 .= $str3 ;
echo $str1;
echo $str2;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The str1 .= str2 is a shorthand for str1 = str1.str2 and this is evaluated from right to left.
- What will be the output of the following PHP code ?
<?php
$k = 15;
--$k;
echo $k++;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The + operator does union of arrays in that order, then the === operator compares key and value pairs.