Interview MCQ Set 1
1. What will be the output of the following PHP code?
-
<?php
-
$title = "O'malley wins the heavyweight championship!";
-
echo ucwords($title);
-
?>
a) O’Malley Wins The Heavyweight Championship!
b) O’malley Wins The Heavyweight Championship!
c) O’Malley wins the heavyweight championship!
d) o’malley wins the heavyweight championship!
Answer
Answer: d [Reason:] The ucwords() function capitalizes the first letter of each word in a string. Its prototype follows: string ucwords(string str).
2. What will be the output of the following PHP code?
-
<?php
-
echo str_pad("Salad", 5)." is good.";
-
?>
a) SaladSaladSaladSaladSalad is good
b) is good SaladSaladSaladSaladSalad
c) is good Salad
d) Salad is good
Answer
Answer: d [Reason:] The str_pad() function pads a string with a specified number of characters.
3. What will be the output of the following PHP code?
-
<?php
-
$str = "Hello World"
-
echo wordwrap($str,5,"<br>n");
-
?>
a) Hello World
b) Hello
World
c) Hell
o wo
rld
d) World
Answer
Answer: b [Reason:] The wordwrap() function wraps a string into new lines when it reaches a specific length.
4. What will be the output of the following PHP code?
-
<?php
-
echo ucwords("i love my country");
-
?>
a) I love my country
b) i love my Country
c) I love my Country
d) I Love My Country
Answer
Answer: d [Reason:] The ucwords() function converts the first character of each word in a string to uppercase.
5. What will be the output of the following PHP code?
-
<?php
-
echo lcfirst("welcome to India");
-
?>
a) welcome to India
b) welcome to india
c) Welcome to India
d) Welcome to india
Answer
Answer: a [Reason:] The lcfirst() function converts the first character of a string to lowercase.
6. What will be the output of the following PHP code?
-
<?php
-
echo hex2bin("48656c6c6f20576f726c6421");
-
?>
a) Hello World!
b) welcome to india
c) This is PHP!
d) MCQ questons
Answer
Answer: a [Reason:] The hex2bin() function converts a string of hexadecimal values to ASCII characters.
7. What will be the output of the following PHP code?
-
<?php
-
$str = addslashes('What does "yolo" mean?');
-
echo($str);
-
?>
a) What does /”yolo/” mean?
b) What does ”yolo” mean?
c) What does ”yolo” mean?
d) What does ”yolo” mean?
Answer
Answer: c [Reason:] The addslashes() function returns a string with backslashes in front of predefined characters.
8. What will be the output of the following PHP code?
-
<?php
-
$str = "Hello world. It's a beautiful day.";
-
print_r (explode(" ",$str));
-
?>
a) Array ( [0] => Hello [0] => world. [0] => It’s [0] => a [0] => beautiful [0] => day. )
b) Array ( [0] => Hello [1] => world. [2] => It’s [3] => a [4] => beautiful [5] => day. )
c) Hello world. It’s a beautiful day
d) Array ( [1] => Hello [2] => world. [3] => It’s [4] => a [5] => beautiful [6] => day. )
Answer
Answer: b [Reason:] The explode() function breaks a string into an array.
9. What will be the output of the following PHP code?
-
<?php
-
echo strtr("Hilla Warld","ia","eo");
-
?>
a) Hilla Warld
b) Hello World
c) ia
d) eo
Answer
Answer: b [Reason:] The strtr() function translates certain characters in a string.
10. What will be the output of the following PHP code?
-
<?php
-
echo stripos("I love php, I love php too!","PHP");
-
?>
a) 3
b) 7
c) 8
d) 10
Answer
Answer: b [Reason:] The stripos() function finds the position of the first occurrence of a string inside another string.
Interview MCQ Set 2
1. What will be the output of the following PHP code ?
-
<?php
-
$a = "$winner";
-
$b = "/$looser";
-
echo $a,$b;
-
?>
a) $winner/$looser
b) /$looser
c) /
d) $looser
Answer
Answer: c [Reason:] Since variables $winner and $looser is not defined we only see / as output.
2. What will be the output of the following PHP code ?
-
<?php
-
$a = "$winner";
-
$b = "$looser";
-
echo $a, $b;
-
?>
a) $winner$looser
b) $looser
c)
d) $looser
Answer
Answer: d [Reason:] As there is a backslash before $ it takes it as a string and not a variable therefore we get $looser as the output.
3. What will be the output of the following PHP code ?
-
<?php
-
$a = "$winner";
-
$b = "$looser";
-
echo $a, $b;
-
?>
a) $winner$looser
b) $looser
c)
d) $looser
Answer
Answer: c [Reason:] Since two backslashes are used together, a single backslash is printed on the screen and as $looser is not initialised only single backslash is printed.
4. What will be the output of the following PHP code ?
-
<?php
-
$x = 5;
-
$y = 10;
-
function fun()
-
{
-
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
-
}
-
fun();
-
echo $y;
-
?>
a) 5
b) 10
c) 15
d) Error
Answer
Answer: c [Reason:] You can access the global variable using $GLOBALS[‘globalvariablename’].
5. What will be the output of the following PHP code ?
-
<?php
-
$x = 5;
-
$y = 10;
-
function fun()
-
{
-
$y = $GLOBALS['x'] + $GLOBALS['y'];
-
}
-
fun();
-
echo $y;
-
?>
a) 5
b) 10
c) 15
d) Error
Answer
Answer: b [Reason:] The value of global variable y does not change therefore it’ll print 10;
6. What will be the output of the following PHP code ?
-
<?php
-
function fun()
-
{
-
$x = 0;
-
echo $x;
-
$x++;
-
}
-
fun();
-
fun();
-
fun();
-
?>
a) 012
b) 123
c) 000
d) 111
Answer
Answer: c [Reason:] Every time the function is called the value of x becomes 0, therefore we get 0 on every function call.
7. What will be the output of the following PHP code ?
-
<?php
-
function fun()
-
{
-
static $x = 0;
-
echo $x;
-
$x++;
-
}
-
fun();
-
fun();
-
fun();
-
?>
a) 012
b) 123
c) 111
d) Error
Answer
Answer: a [Reason:] When static is used, each time the function is called, that variable will still have the information it contained from the last time the function was called.
8. What will be the output of the following PHP code ?
-
<?php
-
static $x = 0;
-
function fun()
-
{
-
echo $x;
-
$x++;
-
}
-
fun();
-
fun();
-
fun();
-
?>
a) 012
b) 123
c) Nothing
d) Error
Answer
Answer: c [Reason:] Since variable x is not defined inside the function fun(), nothing will be printed.
9. What will be the output of the following PHP code ?
-
<?php
-
$x=0;
-
function fun()
-
{
-
echo $GLOBALS['x'];
-
$GLOBALS['x']++;
-
}
-
fun();
-
fun();
-
fun();
-
?>
a) 000
b) 012
c) 123
d) Error
Answer
Answer: b [Reason:] Since, we are using $GLOBALS[‘x’], the question is similar to question 7.
10. What will be the output of the following PHP code ?
-
<?php
-
$x = 0;
-
function fun()
-
{
-
echo $GLOBALS['x'];
-
$x++;
-
}
-
fun();
-
fun();
-
fun();
-
?>
a) 000
b) 012
c) Nothing
d) Error
Answer
Answer: a [Reason:] This question is similar to question 6.
Interview MCQ Set 3
1. What will be the output of the following PHP code ?
-
<?php
-
$i = 0; $j = 1; $k = 2;
-
print !(($i + $k) < ($j - $k));
-
?>
a) 1
b) true
c) false
d) 0
Answer
Answer: a [Reason:] True is 1.
2. What will be the output of the following PHP code ?
-
<?php
-
$i = 0;$j = 1;$k = 2;
-
print !(( + + $i + $j) > ($j - $k));
-
?>
a) 1
b) no output
c) error
d) 0
Answer
Answer: b [Reason:] The equation outputs false .
3. What will be the output of the following PHP code ?
-
<?php
-
$i = 0;$j = 1;$k = 2;
-
print (( + + $i + $j) >! ($j - $k));
-
?>
a) 1
b) no output
c) error
d) 0
Answer
Answer: a [Reason:] Negation of a number is 0.
4. What will be the output of the following PHP code ?
-
<?php
-
$a = 0x6db7;
-
print $a<<6;
-
?>
a) 1797568
b) no output
c) error
d) 0x6dc0
Answer
Answer: a [Reason:] The output is in decimal.
5. What will be the output of the following PHP code ?
-
<?php
-
$a = 'a' ;
-
print $a * 2;
-
?>
a) 192
b) 2
c) error
d) 0
Answer
Answer: d [Reason:] Characters cannot be multiplied.
6. What will be the output of the following PHP code ?
-
<?php
-
$a = '4' ;
-
print + + $a;
-
?>
a) no output
b) error
c) 5
d) 0
Answer
Answer: c [Reason:] The character is type casted to integer before multiplying.
7. What will be the output of the following PHP code ?
-
<?php
-
$a = '12345';
-
print "qwe{$a}rty";
-
?>
a) qwe12345rty
b) qwe{$a}rty
c) error
d) no output
Answer
Answer: a [Reason:] {$}dereferences the variable within.
8. What will be the output of the following PHP code ?
-
<?php
-
$a = '12345';
-
print "qwe".$a."rty";
-
?>
a) qwe12345rty
b) qwe$arty
c) error
d) no output
Answer
Answer: a [Reason:] . dereferences the variable/string within.
9. What will be the output of the following PHP code ?
-
<?php
-
$a = '12345';
-
echo 'qwe{$a}rty';
-
?>
a) qwe12345rty
b) qwe{$a}rty
c) error
d) no output
Answer
Answer: b [Reason:] qwe{$a}rty, single quotes are not parsed.
10. What will be the output of the following PHP code ?
-
<?php
-
$a = '12345';
-
echo "qwe$arty";
-
?>
a) qwe12345rty
b) qwe$arty
c) qwe
d) error
Answer
Answer: c [Reason:] qwe, because $a became $arty, which is undefined.
Interview MCQ Set 4
1. What will be the output of the following PHP code ?
-
<?php
-
$age = array("Harry" => "21", "Ron" => "23","Malfoy" => "21");
-
array_change_key_case($age, CASE_UPPER);
-
array_pop($age);
-
print_r($age);
-
?>
a) Array ( [Harry] => 21 [Ron] => 23 [Malfoy] => 21 )
b) Array ( [HARRY] => 21 [RON] => 23 [MALFOY] => 21 )
c) Array ( [HARRY] => 21 [RON] => 23 )
d) Array ( [Harry] => 21 [Ron] => 23 )
Answer
Answer: c [Reason:] The array_change_key_case() function changes all keys in an array to lowercase or uppercase and arry_pop() removes last element
2. What will be the output of the following PHP code ?
-
<?php
-
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
-
$result = array_flip($a1);
-
print_r($result);
-
?>
a) Array ( [red] => red [green] => green [blue] => blue [yellow] => yellow )
b) Array ( [a] => a [b] => b [c] => c [d] => d )
c) Array ( [red] => a [green] => b [blue] => c [yellow] => d )
d) Array ( [a] => red [b] => green [c] => blue [d] => yellow )
Answer
Answer: c [Reason:] The array_flip() function flips/exchanges all keys with their associated values in an array.
3. What will be the output of the following PHP code ?
-
<?php
-
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
-
$a2 = array("e" => "red","f" => "green", "g" => "blue");
-
$result = array_intersect($a1, $a2);
-
print_r($result);
-
?>
a) Array ( [a] => red [b] => green [c] => blue )
b) Array ( [a] => red [b] => green [c] => blue [d] => yellow )
c) Array ( [e] => red [f] => green [g] => blue )
d) Array ( [a] => red [b] => green [c] => blue [d] => yellow [e] => red [f] => green [g] => blue )
Answer
Answer: a [Reason:] The array_intersect() function compares the values of two (or more) arrays, and returns the matches.
4. What will be the output of the following PHP code ?
-
<?php
-
$a = array(12, 5, 2);
-
echo(array_product($a));
-
?>
a) 024
b) 120
c) 010
d) 060
Answer
Answer: b [Reason:] The array_product() function calculates and returns the product of an array.
5. What will be the output of the following PHP code ?
-
<?php
-
$a = array("a" => "Jaguar", "b" => "Land Rover", "c" => "Audi", "d" => "Maseratti");
-
echo array_search("Audi", $a);
-
?>
a) a
b) b
c) c
d) d
Answer
Answer: c [Reason:] The array_search() function searches for the element and returns the key of that element.
6. What will be the output of the following PHP code ?
-
<?php
-
$city_west = array("NYC", "London");
-
$city_east = array("Mumbai", "Beijing");
-
print_r(array_replace($city_west, $city_east));
-
?>
a) Array ( [1] => Mumbai [0] => Beijing )
b) Array ( [0] => NYC [1] => London )
c) Array ( [1] => NYC [0] => London )
d) Array ( [0] => Mumbai [1] => Beijing )
Answer
Answer: d [Reason:] The array_replace() function replaces the values of the first array with the values from following arrays
7. What will be the output of the following PHP code ?
-
<?php
-
$people = array("Peter", "Susan", "Edmund", "Lucy");
-
echo pos($people);
-
?>
a) Lucy
b) Peter
c) Susan
d) Edmund
Answer
Answer: b [Reason:] The pos() function returns the value of the current element in an array, and since no operation has been done, the current element is the first element.
8. What will be the output of the following PHP code ?
-
<?php
-
$number = range(0, 5);
-
print_r ($number);
-
?>
a) Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
b) Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 )
c) Array ( [0] => 5 [1] => 5 [2] => 5 [3] => 5 [4] => 5 [5] => 5 )
d) Array ( [0] => 0 [5] => 5 )
Answer
Answer: a [Reason:] The range() function creates an array containing a range of elements.
9. What will be the output of the following PHP code ?
-
<?php
-
$array = array("red", "green");
-
array_push($array, "blue", "yellow");
-
print_r($array);
-
?>
a) Array ( [0] => red [1] => green [2] => blue [3] => yellow )
b) Array ( [0] => blue [1] => yellow [2] => red [3] => green )
c) Array ( [0] => red [1] => green )
d) Array ( [0] => blue [1] => yellow )
Answer
Answer: a [Reason:] The array_push() function inserts one or more elements to the end of an array.
10. What will be the output of the following PHP code ?
-
<?php
-
$age = array("Harry" => "21", "Ron" => "19", "Malfoy" => "23");
-
ksort($age);
-
foreach($age as $x => $x_value)
-
{
-
echo "Key=" . $x . ", Value=" . $x_value;
-
echo "<br>";
-
}
-
?>
a) Key = Harry, Value = 21
Key = Ron, Value = 21
Key = Malfoy, Value = 23
b) Key = Harry, Value = 21
Key = Ron, Value = 19
Key = Malfoy, Value = 23
c) Key = Harry, Value = 21
Key = Malfoy, Value = 23
Key = Ron, Value = 19
d) Key = Ron, Value = 19
Key = Harry, Value = 21
Key = Malfoy, Value = 23
Answer
Answer: c [Reason:] The ksort() function sorts an associative array in ascending order, according to the key.
Interview MCQ Set 5
1. How many types of protocols are important for instant messaging ?
a) 2
b) 3
c) 4
d) All of the mentioned
Answer
Answer: b [Reason:] In an effort to create an interoperability standard between different IM clients, several instant messaging protocols have been created.
2. Point out the correct statement:
a) Every third-party IM clients aim to allow their users to connect to the different major IM services
b) SIP stands for Secure Initiation Protocol
c) XMPP stands for Extensible Messaging and Presence Protocol
d) All of the mentioned
Answer
Answer: c [Reason:] SIP stands for Session Initiation Protocol.
3. Which of the following protocol is adopted for interoperability by top three IM service providers ?
a) SIP
b) SIMPLE
c) XMPP
d) IMPS
Answer
Answer: b [Reason:] They allow their users to connect with the other services’ public users for a fee.
4. Which of the following protocol is not a Internet Engineering Task Force standard ?
a) SIP
b) SIMPLE
c) XMPP
d) IMPS
Answer
Answer: d [Reason:] IMPS is IM communications standard.
5. Point out the wrong statement:
a) All IM clients use peer-to-peer messaging
b) IM software aimed at businesses such as XMPP, Lotus Sametime, and Microsoft Office Communicator use a client/server architecture
c) Instant messaging is as popular in business as it is in personal communications
d) None of the mentioned
Answer
Answer: d [Reason:] Some IM clients use peer-to-peer messaging.
6. Which of the following IM client allow their users to connect to the different major IM services ?
a) Pidgin
b) Miranda IM
c) Trillian
d) All of the mentioned
Answer
Answer: d [Reason:] Trillian runs on Windows, Macintosh, IOS (iPhone OS), Android, Blackberry, and inside browsers.
7. Which of the following is also referred to as Short Message Service ?
a) Mini-blogs
b) Micro-blogs
c) Nano-blogs
d) None of the mentioned
Answer
Answer: b [Reason:] When a service collects your messages in a conversation, it is called a micro-blog.
8. Which of the following is a good example of an SMS service organized into a social network and blog ?
a) Twitter
b) Facebook
c) Instagram
d) None of the mentioned
Answer
Answer: a [Reason:] It is sometimes referred to as the SMS of the Internet or as a form of Internet Relay Chat (IRC).
9. Which of the following language is used to build message server queue in twitter ?
a) Ruby
b) Scala
c) Java
d) All of the mentioned
Answer
Answer: b [Reason:] The Twitter Web client was built using Ruby on Rails and deployed on the Ruby Enterprise Edition, with the message queue server written in Scala.
10. Which of the following version of office suite is shown in the figure ?
a) Offline
b) Online
c) Online and Offline
d) None of the mentioned
Answer
Answer: b [Reason:] Glide Digital OS4 is a complete suite with office software, e-mail, and other tools that replicate an online desktop.