Categories
PHP

PHP Interview Questions part 1

1. Find the output of :
srand(time());
$a = rand(1,2);
if($a==0) {
echo “Red”;
}
else if($a>2) {
echo “White”;
}
else if($a) {
echo “Blue”;
}
else if($a=1) {
echo “Green”;
}
else
{
echo “Clear”;
}
a.) Red
b.) White
c.) Blue
d.) Green
e.) Clear

2. Find the output of :
echo substr(”artichoke”,-3,-2);
a.) ar
b.) ho
c.) rtic
d.) o
e.) oke

3. The PHP syntax is most similar to:
a.) VB Script
b.) P
erl and C
c.) .Net
4. What is the output of this PHP code?
$list = array(”clock”,”scissors”,”pen”,”yak”);
$list[] = “cow”;
$list[] = “dragon”;
print “$list[4]”;
a.) clock,scissors,pen,yak
b.) yak
c.) cow
d.) dragon
e.) pen

5. Find the output:
if ((string)’-1′)
{
print ‘ouch’;
}
else
{
print ‘echo’;
}
a.) None
b.) echo
c.) ouch


6. What is the out of this code?

$x=”3.14″;
if (is_float($x) == TRUE)
{
$y=(int)$x;
} printf(”%-02s$x”,$y);
a.) 003.14
b.) 003
c.) -02s3.14
d.) -33.14
e.) 303.14


7. In PHP, what is the output here?
$x = “”;
switch ($x) {
case “0″: echo “String”; break;
case 0: echo “Integer”; break;
case NULL: echo “NULL”; break;
case FALSE: echo “Boolean”; break;
case “”: echo “Empty string”; break;
default: echo “Something else”; break;
}
a.) String
b.) Integer
c.) NULL
d.) Boolean
e.) Empty string
f.) Something else

8. What is the output for:
$a=htmlspecialchars(”O\’Hare & Max was here!”);
echo substr_count($a,”&”);
a.) 5
b.) 8
c.) 1
d.) 0

9. What is the value of $y after execution:
do {
$x=mktime(12,5,30,2,20,1985-$n++);
$y++;
} while($x>0);
a.) 1
b.) 5
c.) 9
d.) 15
e.) 17

———————————
Answers

1. c.) Blue

2. d.) o
3. b.) Perl and C
4. c.) cow
5. c.) ouch
6. a.) 003.14
7. b.) Integer
8. c.) 1
9. e.) 17