IP 621
B. i), ii) and iii)
C. All of the mentioned
D. None of the mentioned
ANS: C
16. If $a = 12 what will be returned when ($a == 12)? 5:1 is executed?
A. 12
B. 1
C. Error
D. 5
ANS: D
17. What will be the output of the following PHP code?
<?php
$x;
if ($x)
print "hi" ;
else
print "how are u";
?>
A. how are u
B. hi
C. Error
D. No output
IP 621
ANS: B
18. PHP scripts are executed on __________________
A. ISP computer
B. Client computer
C. Server computer
D. Depends on script
ANS: C
19. In PHP each statement must end with _____________
A. . (dot)
B. ;(semi-colon)
C. /(slash)
D. :(colon)
ANS: B
20. In PHP language variable names start with ____________
A. !(Exclamation)
B. &(Ampersand)
C. *(Asterisk)
D. $(Dollar)
ANS: D
21. In PHP one needs to declare variables before assigning values to them.
IP 621
A. True
B. False
C. Depends on the server
D. Depends on the site
ANS: B
22. Which of the following is the Concatenation operator in PHP?
A. +(Plus)
B. .(dot)
C. &(Apersand)
D. %(Percent)
ANS: B
23. How to define a variable in PHP
A. $variable_name = value
B. $variable_name = value;
C. $variable_name == value;
D. $variable_name as value;
ANS: B
24. What is the result of combining a string with another data type in PHP?
A. int
B. float
C. string
D. double
IP 621
ANS: C
25. PHP is a _____________ typed language
A. User
B. Loosely
C. Server
D. System
ANS: B
26. What does the PHP interpreter do?
A. It translates User language to System Language
B. It creates connection between ISP and Server
C. It processes the HTML and PHP files
D. All of the above
ANS: C
27. How are PHP files accessed?
A. Through the Web Browser
B. Through HTML files
C. Through the Web Server
D. All of the above
ANS: C
28. Variables in PHP are case sensitive
A. True
B. False
IP 621
C. Depends on server
D. Depends on browser
ANS: A
29. What will be the output of the following PHP code?
<?php
$a = 10;
echo ++$a;
echo $a++;
echo $a;
echo ++$a;
?>
A. 11111213
B. 11121213
C. 11111212
D. 11111112
ANS: A
30. What will be the output of the following PHP Code?
<?php
$a = 12;
--$a;
Echo $a++;
?>
A. 11
B. 12
C. 10
D. error
ANS: A
31. Trace the odd data type
A. floats
IP 621
B. integer
C. doubles
D. Real number
ANS: D
32. In php string data are
A. delimited by single quote
B. delimited by double quote
C. delimited by <<< identifier
D. All of above
ANS: B
32. Which data types are treated as arrays
A. Integer
B. Float
C. String
D. Booleans
ANS: C
33. When defining identifier in PHP you should remember that
A. Identifiers are case sensitive. So $result is different than $Result
B. Identifiers can be any length
C. Both of above
D. None of above
ANS: C
IP 621
34. Identify the invalid identifier
A. my_function
B. size
C. _some word
D. This&that
ANS: D
35. The left associative dot operator (.) is used in PHP for
A. multiplication
B. concatenation
C. separate object and its member
D. delimeter
ANS: B
36. Which of following are compound data types?
A. Array
B. Objects
C. Both of the above
D. None of the above
ANS: C
37. What will be the output of the following PHP code ?
<?php
$x = 10;
$y = 20;
if ($x > $y + $y != 3)
print "hi" ;
IP 621 else
?> print "how are u";
A. how are u
B. hi
C. Error
D. No output
ANS: B
38. What will be the output of the following PHP code?
<?php
$x = 1;
if ($x == 2)
print "hi" ;
else if($x = 2)
print $x;
else
print "how are u";
?>
A. error
B. 2
C. hi
D. how are u
ANS: B
IP 621
39. What will be the output of the following PHP code?
<?php
$a = 100;
if ($a > 10)
printf("M.S. Dhoni");
else if ($a > 20)
printf("M.E.K Hussey");
else if($a > 30)
printf("A.B. de villiers");
?>
A. M.S.Dhoni
B. M.E.K.Hussey
C. M.S.Dhoni
M.E.K.Hussey
A.B.de villiers
D. no output
ANS: A
40. What will be the output of the following PHP code ?
<?php
"Hello World"
?>
A. Error
B. Hello World
IP 621
C. Nothing
D. Missing semicolon error
ANS: C
41. What will be the output of the following PHP code ?
<?php
# echo "Hello world";
echo "# Hello world";
?>
A. # Hello world
B. Hello world# Hello world
C. Hello world
D. Error
ANS: A
42. What will be the output of the following PHP code ?
<?php
/*
echo "Hello world";
*/
?>
A. Hello world
IP 621
B. Nothing
C. error
D. /*
Hello world
*/
ANS: B
43. What will be the output of the following PHP code?
<?php
$color = "red";
$color = "green";
echo "$color";
?>
A. red
B. green
C. red green
D. error
ANS: B
44. 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
IP 621
C. false
D. 0
ANS: A
45. What will be the output of the following PHP code?
<?php
define("GREETING", "PHP is a scripting language", true);
echo GREETING;
echo "<br>"
echo GREETING;
?>
A. PHP is a scripting language
B. GREETING
GREEtING
C. GREETING
D. PHP is a scripting language
PHP is a scripting language
ANS: D
46. What will be the output of the following PHP code ?
<?php
$i = 0
do
{
IP 621 print "hi";
$i++;
?> }
A. hi while ($i != 3);
hi
B. hi
C. hi
hi
hi
hi
D. no output
ANS: C
47. What will be the output of the following PHP code ?
<?php
$i = 5;
while (--$i > 0)
{
$i++; print $i; print "hello";
}
?>
A. 4hello4hello4hello4hello4hello…..infinite
B. 5hello5hello5hello5hello5hello…..infinite
IP 621
C. no output
D. error
ANS: A
48. What will be the output of the following PHP code?
<?php
$i = 5;
while (--$i > 0 && ++$i)
{
print $i;
}
?>
A. 5
B. 555555555…infinitely
C. 54321
D. error
ANS: B
49. What will be the output of the following PHP code?
<?php
$a = "1";
switch($a)
{
case 1:
break;
print "hi";
IP 621
case 2:
print "hello";
break;
default:
print "hi1";
}
?>
A. hihellohi1
B. no output
C. hihi1
D. hi1
ANS: B
50. What will be the output of the following PHP code?
<?php
$a = 5;
$b = 5;
echo ($a === $b);
?>
A. 5 === 5
B. Error
C. 1
D. False
ANS: C
IP 621
51. An unitialised variable in PHP is given a default value of ____________
A. 0 (zero)
B. null
C. default
D. None of the above
ANS: B
52. PHP allows you to use variables at any point of the script without having explicitly declared them
prior
A. True
B. False
ANS: A
53. Which two compound data types are supported by PHP?
A. Array and Integer
B. Array and float
C. Float and Integer
D. Array and Object
ANS: D
54. Finally, PHP supports two special data types, so called because they don’t contain scalar or
compound data. Identify two special data types supported by PHP
A. Array and Object
B. Integer and Float
C. Resource and Null
IP 621
D. None of the above
ANS: C
55. Consider the following code block:
<php
$testVar;
$testVar = “moodley”;
$testVar = 89.6;
$testVar = 67;
echo gettype($testVar);
?>
The output of this program is:
A. error
B. String
C. Integer
D. Double
ANS: C
56. Consider the following code block
<?php
$test_var = 8.23;
settype( $test_var, “integer” );
echo $test_var . “ < br / > ”;
?>
The output of this program is _____________
A. 8.23
B. 8
C.8.0
IP 621
D. 8.2
ANS: B
57. PHP is an interpreted language,
A. True
B. False
ANS: A
58. Which statement is not true about PHP?
A. PHP is a server side scripting language
B. PHP is a client side scripting language
C. PHP is used to make websites dynamic and interactive
D. PHP code can be imbedded within HTML code
ANS: B
59. Which option does not apply to the php.ini file?
A. The php.ini file can be used to specify the maximum size of files that a user can upload
B. The php.ini file can be used to set the folder and cookie settings
C. The php.ini file is read by the PHP engine when PHP starts
D. The php.ini file is used to close all internet connections
ANS: D
60. All of the following can be used as identifiers (variable names) in PHP except __________
A. $_account_name
B. $23Account
C. $aVeryLongVariableName
IP 621
D. $abc123
ANS: B
61. PHP can run on different platforms e.g. Windows and Linux
A. True
B. False
ANS: A
62. What is the output of the following code block?
<?php
$x = 6;
$y = 13;
echo $x + $y;
?>
A. 19
B. xy
C. 613
D. $x+$y
ANS: A
63. Which extension is the correct php file extension?
A. .php
B. .pxhtml
C. .php33a
D. .phxml4
IP 621
ANS: A
64. Which of the following is the incorrect way to declare a PHP variable?
A. $aVariable;
B. $a_Variable = 9;
C. $AVariable;
D. $a Variable;
ANS: D
65. PHP variables need to be declared before adding a value to it?
A. True
B. False
ANS: B
66. What data type will PHP automatically convert the following variable to? $aVariable = 99;
A. integer (a number variable)
B. string (a text variable)
ANS: A
67. Which of the following is the incorrect way to declare a PHP variable?
A. $a_Number = 9
B. $a_Number = 9;
C. $a_Num = 9;
D. $aNumber = 9;
ANS: A
IP 621
68. Look at the following code and determine what will be displayed in the browser:
<?php
echo “Hello World 1”;
// echo “Hello World 2”;
?>
A. Hello World 1 Hello World 2
B. Hello World 2
C. Hello World 1
D. Hello World 2 Hello World 1
ANS: C
69. You can use HTML tags within an echo string?
A. True
B. False
ANS: A
70. From the following php scripting block, what will be displayed in the browser:
<?php
$aVariable = “Hello Robert”;
echo “$aVariable”;
?>
A. Hello
B. aVariable
IP 621
C. Hello Robert
D. None of the above
ANS: C
71. Which of the following is the incorrect way to echo a variable?
A. echo “$aVariable”;
B. echo $aVariable;
C. All of the above
D. None of the above
ANS: C
72. If the variable $x = 10; what will $x equal if it is incremented, that is, if I write $x++; what value will
$x contain after it has been incremented?
A. 9
B. 10
C. 11
D. 12
ANS: C
73. The following example $a -= $b; is the same as?
A. $b = $a – $b;
B. $a = $a – $b;
C. $a = $b – $a;
D. $b = $b – $a;
ANS: B
IP 621
74. The logical operator && stands for?
A. OR
B. AND
C. NOT
D. None of the above
ANS: B
75. The logical operator || stands for?
A. OR
B. AND
C. NOT
D. None of the above
ANS: A
76. The following condition will return TRUE or FALSE:
(4 >= 4 && 8 < 1)
A. TRUE
B. FALSE
ANS: B
77. The following condition will return TRUE or FALSE
((4 >= 4 && 8 < 1) || (44 == 33 || 5 > 3))
A. TRUE
B. FALSE
ANS: A
IP 621
78. What will be displayed in a browser when the following PHP code is executed?
<?php
if (8 >= 7) {
echo "Hello World";
}
?>
A. Hello World
B. Nothing Will Be Displayed
C. True
D. TrueHello World
ANS: A
79. What will be displayed in a browser when the following PHP code is executed:
<?php
if (8 >= 7 && "Tom" == "Rose") {
echo "Hello World";
}
?>
A. Hello World
B. Nothing Will Be Displayed
ANS: B
80. What will be displayed in a browser when the following PHP code is executed:
<?php
IP 621
if (8 >= 7 || "Tom" == "Rose") {
echo "Hello World";
}
?>
A. Hello World
B. Nothing Will Be Displayed
ANS: A
81. The PHP If Statement will only execute the code within it’s curly braces if the if condition is FALSE?
A. True
B. False
ANS: B
82. What will be displayed in a browser when the following PHP code is executed:
<?php
if (8 <= 7) {
echo "Hello World";
}
else {
echo "Hello YouTube";
}
?>
A. Hello World
IP 621
B. Hello YouTube
C. Hello World Hello YouTube
D. Nothing Will Be Displayed
ANS: B
83. The PHP If Else Statement can execute the code within the if and else segments at the same time?
A. True
B. False
ANS: B
84. What will be displayed in a browser when the following PHP code is executed:
<?php
$bookColor = "red";
$bookName = "The PHP Basics";
if ($bookColor == "red" && $bookName == "Steve Jobs") {
echo "You have the wrong book";
}
else {
echo "You might have the right book";
}
?>
A. You have the wrong book
B. You might have the right book
IP 621
C. Nothing Will Be Displayed
D. False
ANS: B
85. What will be displayed in a browser when the following PHP code is executed:
<?php
$x = 6;
$y = 4;
$sum = $x + $y; //sum = 10
$ten = "Ten";
if ($sum >= 10 && $ten == "Ten") {
$answer = "Correct";
echo "Your answer is: $answer";
}
else {
$answer = "Incorrect";
echo "Your answer is: $answer";
}
?>
A. Your answer is: Incorrect
B. Your answer is: $answer
C. Your answer is: Correct
D. Nothing Will Be Displayed
ANS: C
IP 621
86. Which of the following cases is a correct way to write a case for a switch statement?
A. case “Mark”;
B. case “Mark”::
C. case “Mark”:
D. case “Mark”{
ANS: C
87. The default case is executed if all the other cases for a switch statement evaluate to false?
A. True
B. False
ANS: A
88. What will be displayed in a browser when the following PHP code is executed:
<?php
$variable = 2;
switch ($variable) {
case 1:
echo "Hello World";
break;
default:
echo "Hello Channel";
break;
}
?>
IP 621
A. Hello World
B. Hello Channel
C. Nothing Will Be Displayed
D. $variable
ANS: B
89. What will be displayed in a browser when the following PHP code is executed:
<?php
$variable = 1;
switch ($variable) {
case 1:
echo "Hello World";
default:
echo "Hello Channel";
break;
}
?>
A. Hello World
B. Hello Channel
C. Hello WorldHello Channel
D. Nothing Will Be Displayed
ANS: C
90. What is missing from case 2 in the switch statement below?
IP 621
<?php
$variable = 1;
switch ($variable) {
case 1:
echo "Hello World";
break;
case 2:
echo "Hello Tom";
default:
echo "Hello Robert";
break;
}
?>
A. break:
B. break()
C. break;
D. None of the above
ANS: C
91. A while loop will continue to execute a segment of code until its condition evaluates to false?
A. True
B. False
ANS: A
92. A while loop is preferred when having to carry out a repetitive operation?
IP 621
A. True
B. False
ANS: A
93. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 1;
while ($counter <= 5) {
$counter++;
}
echo "Counter is: $counter";
?>
A. Counter is: 1
B. Counter is: 5
C. Counter is: 4
D. Counter is: 6
ANS: D
94. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 6;
while ($counter != 3) {
echo "Hello World | ";
$counter--;
}
?>
IP 621
A. Hello World | Hello World |
B. Hello World | Hello World | Hello World |
C. Hello World | Hello World | Hello World | Hello World |
D. None of the above
ANS: B
95. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 3;
while ($counter != 3) {
echo "Hello World | ";
$counter--;
} ?>
A. Hello World | Hello World
B. Hello World | Hello World | Hello World
C. Hello World | Hello World | Hello World | Hello World
D. None of the above
ANS: D
96. A do while loop will execute a segment of code at least one time?
A. True
B. False
ANS: A
IP 621
97. A do while loop will check the while condition before executing the segment of code between the
curly braces?
A. True
B. False
ANS: B
98. Is the following a correct example for a PHP do while loop?
<?php
$counter = 1;
do while ($counter < 5);{
$counter++;
}
echo "Counter is: $counter";
?>
A. Yes
B. No
ANS: B
99. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 1;
do while ($counter < 5);{
$counter++;
}
echo "Counter is: $counter";
IP 621
?>
A. Counter is: 4
B. Counter is: 5
C. Counter is: 2
D. None of the above
ANS: D
100. What will be displayed in a browser when the following PHP code is executed:
<?php
$counter = 1;
do {
$counter++;
} while ($counter < 0);
echo "Counter is: $counter";
?>
A. Counter is: 4
B. Counter is: 5
C. Counter is: 2
D. None of the above
ANS: C
101. A for loop contains an initializing expression, a condition statement expression, and an increment
expression?
IP 621
A. True
B. False
ANS: A
102. A for loop will check the condition statement before executing the segment of code between the
curly braces?
A. True
B. False
ANS: A
103. What will be displayed in a browser when the following PHP code is executed?
<?php
for ($counter = 20; $counter < 10; $counter++){
echo "Hello Robert ";
}
echo "Counter is: $counter";
?>
A. Hello Robert
B. Counter is: 20
C. Hello Robert Counter is: 22
D. Hello Robert Hello Robert Counter is: 22
ANS: B
IP 621
104. What will be displayed in a browser when the following PHP code is executed:
<?php
for ($counter = 15; $counter != 10; $counter--){
echo "Hello ";
}
?>
A. Hello Hello
B. Hello Hello Hello
C. Hello Hello Hello Hello Hello
D. None of the above
ANS: C
105. What will be displayed in a browser when the following PHP code is executed:
<?php
for ($counter = 10; $counter < 10; $counter = $counter + 5){
echo "Hello";
}
?>
A. Hello Hello Hello Hello Hello
B. Hello Hello Hello
C. Hello
D. None of the above
ANS: D
IP 621
106. Which of the following is correct about variable naming rules?
A. Variable names must begin with a letter or underscore character.
B. A variable name can consist of numbers, letters, underscores.
C. You cannot use characters like + , - , % , ( , ) . & , etc in a variable name.
D. All of the above.
ANS: D
107. Which of the following is correct about constants?
A. To define a constant you have to use define() function.
B. To retrieve the value of a constant, you have to simply specify its name.
C. Both of the above.
D. None of the above.
ANS: C
108. Which of the following is correct about constants vs variables in PHP?
A. There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a
dollar sign.
B. Constants cannot be defined by simple assignment, they may only be defined using the define()
function.
C. Both of the above.
D. None of the above.
ANS: C
109. Which of the following keyword terminates the for loop or switch statement and transfers
execution to the statement immediately following the for loop or switch?
A. break
IP 621
B. continue
C. All of the above
D. None of the above
ANS: A
110. Which of the following keyword causes the loop to skip the remainder of its body and immediately
retest its condition prior to reiterating?
A. break
B. continue
C. All of the above
D. None of the above
ANS: B
111. How does the identity operator === compare two values? compares the resulting values
A. It converts them to a common compatible data type and then
B. It returns True only if they are both of the same type and value
C. If the two values are strings, it performs a lexical comparison
D. t bases its comparison on the C strcmp function exclusively
ANS: A
112. Variables always start with a _______ in PHP
A. Pond-sign
B. Yen-sign
C. Dollar-sign
D. None of the Above
IP 621
ANS: C
113. PHP is an open source software
A. True
B. False
ANS: A
114. Which of the following is not valid PHP code?
A. $_10
B. ${?MyVar?}
C. &$something
D. $10_somethings
ANS: D
115. What is the difference between print() and echo()?
A. print() can be used as part of an expression, while echo() cannot
B. echo() can be used as part of an expression, while print() cannot
C. echo() can be used in the CLI version of PHP, while print() cannot
D. both A and B
ANS: A
IP 621
116. How would you add 1 to the variable $count?
A. incr count;
B. $count++;
C. $count =+1
D. incr $count;
ANS: B
117. PHP variables are _____________
A. Multitype variables
B. Double type variables
C. Single type variable
D. Trible type variables
ANS: A
118. A script is a _____________
A. Program or sequence of instructions that is interpreted or carried out by processor directly
B. Program or sequence of instruction that is interpreted or carried out by another program
C. Program or sequence of instruction that is interpreted or carried out by web server only
D. None of above
ANS: B
IP 621
119. You can define a constant by using the define() function. Once a constant is defined
A. It can never be changed or undefined
B. It can never be changed but can be undefined
C. It can be changed but cannot be undefined
D. It can be changed and can be undefined
ANS: A
120. What will be the output of the following code block? Assume today is 2009-5-19:19:2:45:32 pm
<?php
$today = date("F j, Y, g:i a");
?>
A. may 19,09,2:45:32 PM
B. May 19, 2009, 2:45 pm
C. May 19,2009,14:45:32 pm
D. May 19,2009,14:45:32 PM
ANS: B
121. Trace the false statement from the following
A. Any code found within an included file will inherit the variable scope of the location of its caller
B. Because the included code will be embedded in a PHP execution block, the PHP execution block, the
PHP escape tags (<?php?> aren’t required on the file to be included.
C. For the inclusion of remote files the allow-url-pope must be enabled ad URL wrapper must be
supported
D. Including a file produces the same result as copying the data from the file specified into the location
in which the statement appears.
ANS: B
122. What will be the output of the following date() function?
IP 621
<?php
$date="2009-5-19";
$time="14:31:38";
$datetime=$date.$time;
echo date("Y-m-d:H:i:s",strtotime($datetime));
?>
A. 2009-5-19:14:31:38
B. 2009-5-19:2:31:38
C. 19-5-2009:2:31:38
D. 19/5/2009:14:31:38
ANS: A
123. PHP code is directly embedded into XHTML document?
A. True
B. False
ANS: A
124.
Topic: 4
1. PHP has long supported two regular expression implementations known as ___ and ___.
i) Perl
ii) PEAR
iii) Pearl
iv) POSIX
a) i) and ii)
b) ii) and iv)
c) i) and iv)
d) ii) and iii)
Answer: c
2. Which one of the following regular expression matches any string containing zero or one p?
a) p+
b) p*
c) P?
d) p#
Answer: c
3. [:alpha:] can also be specified as..
a) [A-Za-z0-9] b) [A-za-z] c) [A-z] d) [a-z] View Answer
4. How many functions does PHP offer for searching strings using POSIX style regular
expression?
a) 7
b) 8
c) 9
d) 10
Answer: a
5. What will be the output of the following PHP code?
<?php
$username = "jasoN";
if (ereg("([^a-z])",$username))
echo "Username must be all lowercase!";
else
echo "Username is all lowercase!";
?>
a) Error
b) Username must be all lowercase!
c) Username is all lowercase!
d) No Output is returned
Answer: b
6. POSIX implementation was deprecated in which version of PHP?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3
Answer: d
7. POSIX stands for
a) Portable Operating System Interface for Unix
b) Portable Operating System Interface for Linux
c) Portative Operating System Interface for Unix
d) Portative Operating System Interface for Linux
Answer: a
8. What will be the output of the following PHP code?
<?php
$text = "this is\tsome text that\nwe might like to parse.";
print_r(split("[\n\t]",$text));
?>
a) this is some text that we might like to parse.
b) Array ( [0] => some text that [1] => we might like to parse. )
c) Array ( [0] => this is [1] => some text that [2] => we might like to parse. )
d) [0] => this is [1] => some text that [2] => we might like to parse.
Answer: d
9. Which of the following would be a potential match for the Perl-based regular expression
/fo{2,4}/ ?
i) fol
ii) fool
iii) fooool
iv) fooooool
a) Only i)
b) ii) and iii)
c) i), iii) and iv)
d) i) and iv)
Answer: b
10. Which among the following is/are not a metacharacter?
i)/a
ii)/A
iii)/b
iv)/B
a) Only i)
b) i) and iii)
c) ii), iii) and iv)
d) ii) and iv)
Answer: i)
11. How many functions does PHP offer for searching and modifying strings using Perl-
compatible regular expressions.
a) 7
b) 8
c) 9
d) 10
Answer: b
12. What will be the output of the following PHP code?
<?php
$foods = array("pasta", "steak", "fish", "potatoes");
$food = preg_grep("/^s/", $foods);
print_r($food);
?>
a) Array ( [0] => pasta [1] => steak [2] => fish [3] => potatoes )
b) Array ( [3] => potatoes )
c) Array ( [1] => steak )
d) Array ( [0] => potatoes )
Answer: c
13. Say we have two compare two strings which of the following function/functions can you
use?
i) strcmp()
ii) strcasecmp()
iii) strspn()
iv) strcspn()
a) i) and ii)
b) iii) and iv)
c) None of the mentioned
d) All of the mentioned
Answer: d
14. Which one of the following functions will convert a string to all uppercase?
a) strtoupper()
b) uppercase()
c) str_uppercase()
d) struppercase()
Answer: a
15. 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: d
16. 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: d
17. Which one of the following functions can be used to concatenate array elements to form a
single delimited string?
a) explode()
b) implode()
c) concat()
d) concatenate()
Answer: b
18. Which one of the following functions finds the last occurrence of a string, returning its
numerical position?
a) strlastpos()
b) strpos()
c) strlast()
d) strrpos()
Answer: d
19. What will be the output of the following PHP code?
<?php
$author = "[email protected]";
$author = str_replace("a","@",$author);
echo "Contact the author of this article at $author.";
?>
a) Contact the author of this article at nachiketh@[email protected]
b) Cont@ct the @uthor of this @rticle @t n@chiketh@[email protected]
c) Contact the author of this article at n@chiketh@[email protected]
d) Error
Answer: c
20. What will be the output of the following PHP code?
<?php
$url = "[email protected]";
echo ltrim(strstr($url, "@"),"@");
?>
a) [email protected]
b) nachiketh
c) nachiketh@
d) example.com
Answer: d
Topic: 5
21. Which one of the following is the right way of defining a function in PHP?
a) function { function body }
b) data type functionName(parameters) { function body }
c) functionName(parameters) { function body }
d) function fumctionName(parameters) { function body }
Answer: d
22. Type Hinting was introduced in which version of PHP?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6
Answer: b
23. What will happen in this function call?
<?php
function calc($price, $tax)
{
$total = $price + $tax;
}
$pricetag = 15;
$taxtag = 3;
calc($pricetag, $taxtag);
?>
a) Call By Value
b) Call By Reference
c) Default Argument Value
d) Type Hinting
Answer: a
24. What will be the output of the following PHP code?
<?php
function calc($price, $tax="")
{
$total = $price + ($price * $tax);
echo "$total";
}
calc(42);
?>
a) Error
b) 0
c) 42
d) 84
Answer: c
25. Which of the following are valid function names?
i) function()
ii) €()
iii) .function()
iv) $function()
a) Only ii)
b) None of the mentioned.
c) All of the mentioned.
d) iii) and iv)
Answer: a
26. What will be the output of the following PHP code?
<?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
a();
a();
?>
a) I am b
b) I am bI am a
c) Error
d) I am a Error
Answer: d
27. What will be the output of the following PHP code?
<?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
b();
a();
?>
a) I am b
b) I am bI am a
c) Error.
d) I am a Error
Answer: c