Friday, August 28, 2015

PHP logical expression and php logic building with increments, decrements, while loop, if else statement

Question 1:

<?php 
$x = 0; 
$y = $x--;
$z = --$x;
echo “x=$x,y=$y,z=$z”
?>
a. x = 0 , y = 0 , z = -1
b. x = -1 , y = -1 , z = -2
c. x = -2 , y = 0 , z = -2
d. x = 0 , y = 0 , z = -2


Question 2:

<?php 
$x = 0; 
$y = --$x  + 1 ;
$z = --$y -1;
echo “x=$x,y=$y,z=$z”
?>
e. x = 0 , y = 0 , z = -2
f. x = -1 , y = -1 , z = -2
g. x = -2 , y = 0 , z = -2
h. x = 0 , y = 0 , z = -2


Question 3:

<?php 
$x = 0; 
$y = $x--;
$z = --$y;
echo “x=$x,y=$y,z=$z”
?>
i. x = -1, y = -1, z = -1
j. x = -1, y = -1, z = -2
k. x = -1, y = -2, z = -2
l. x = 0, y = 0, z = -2

Question 4:

<?php 
$x = 0; 
$y = $x - 1;
$x = $y--;
$z = --$x;
echo “x=$x,y=$y,z=$z”
?>
m. x = 0, y = 0, z = -1
n. x = -1, y = -1, z = -2
o. x = -2, y = 0, z = -2
p. x = -2, y = -2, z = -2

Question 5:

<?php 
$x = -1; 
$y = $x + 1;
$z = ++$x + $y ;
echo “x=$x,y=$y,z=$z”
?>
q. x = 0, y = 0, z = 0
r. x = -1, y = -1, z = -2
s. x = -2, y = 0, z = -2
t. x = 0, y = 0, z = -2

Question 6:

<?php 
$x = 0; 
$y = $x--;
$z = ($x++) + $y;
echo “x=$x,y=$y,z=$z”
?>
u. x = 0, y = 0, z = -1
v. x = -1, y = -1, z = -2
w. x = -2, y = 0, z = -2
x. x = 0, y = 0, z = -2

Question 7:

<?php 
$x = 0; 
$y = (--$x) + 1;
$z = --$x + (++$y);
echo “x=$x,y=$y,z=$z”
?>
y. x = 0, y = 0, z = -1
z. x = -1, y = -1, z = -2
aa. x = -2, y = 1, z = -1
bb. x = 0, y = 1, z = -2


Question 8:

<?php 
$x = 0; 
$y = $x--;
$y = --$x;
$y--;
$z = --$x;
echo “x=$x,y=$y,z=$z”
?>
cc. x = -3, y = -2, z = -3
dd. x = -3, y = -1, z = -3
ee. x = -2, y = -2, z = -2
ff. x = -3, y = -3, z = -3

Question 9:

<?php 
$x = 0; 
$y = $x + 1;
$z = (--$x)  + ($y++);
echo “x=$x,y=$y,z=$z”
?>
gg. x = -1, y = 2, z = -1
hh. x = -1, y = 2 , z = 0
ii. x = -2, y = 1, z = -2
jj. x = -1, y = 2, z = -2

Question 10:
$i = 0;
while($i == 0){
   echo $i;
   $i++;
}
/*
*out put 0
*/

Question 11:
$i = 5;
while($i--){
echo $i . ", ";
}
/*
*out put  4, 3, 2, 1, 0,
*/

Question 12:
$x = -1;
if($x++){
echo "if";
} else {
echo "else";
}
/*
*out put if 
*/

Question 13:
$x = -1;
if(++$x){
echo "if";
} else {
echo "else";
}
/*
*out put else 
*/

No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }