Examveda
Examveda

What will be the output of the following PHP code ?
<?php
$y = 2;
if (--$y == 2 || $y xor --$y)
{
    echo $y;
}
?>

A. 1

B. 0

C. 2

D. no output

Answer: Option B

Solution(By Examveda Team)

–$y == 2 is false but y is decremented, the xor gives true if only one of the operands are true, thus 1 xor 0 is true.

This Question Belongs to PHP >> Operators And Expressions In Php

Join The Discussion

Related Questions on Operators and Expressions in php