R4RIN
Articles
Java 8
MCQS
PHP MCQ Quiz Hub
PHP MCQ– Basics
Choose a topic to test your knowledge and improve your PHP skills
1. What does PHP stand for? i) Personal Home Page ii) Hypertext Preprocessor iii) Pretext Hypertext Processor iv) Preprocessor Home Page
Both i) and iii)
Both ii) and iv)
Only ii)
Both i) and ii)
2. PHP files have a default file extension of_______
.html
.xml
.php
.ph
3. What should be the correct syntax to write a PHP code?
< php >
< ? php ?>
<? ?>
<?php ?>
4. Which of the following is/are a PHP code editor?
Notepad
Notepad++
Adobe Dreamweaver
PDT
5. Which of the following must be installed on your computer so as to run PHP script? i) Adobe Dreamweaver ii) XAMPP iii) Apache and PHP iv) IIS
i), ii), iii) and iv)
Only ii)
ii) and iii)
ii), iii) and iv)
6. Which version of PHP introduced Try/catch Exception?
PHP 4
PHP 5
PHP 6
PHP 5 and later
7. How should we add a single line comment in our PHP code? i) /? ii) // iii) # iv) /* */
Only ii)
i), iii) and iv)
ii), iii) and iv)
Both ii) and iv)
8. Which of the following PHP statement/statements will store 111 in variable num? i) int $num = 111; ii) int mum = 111; iii) $num = 111; iv) 111 = $num;
Both i) and ii)
i), ii), iii) and iv)
Only iii)
Only i)
9. What will be the output of the following PHP code? <?php $num = 1; $num1 = 2; print $num . "+". $num1; ?>
3
1+2
1.+.2
Error
10. Which is the right way of declaring a variable in PHP? i) $3hello ii) $_hello iii) $this iv) $This
Only ii)
Only iii)
ii), iii) and iv)
ii) and iv)
11. What will be the output of the following PHP code? <?php $foo = 'Bob'; $bar = &$foo; $bar = "My name is $bar"; echo $bar; echo $foo; ?>
Error
My name is BobBob
My name is BobMy name is Bob
My name is Bob Bob
12. Which of the following PHP statements will output Hello World on the screen? i) echo ("Hello World"); ii) print ("Hello World"); iii) printf ("Hello World"); iv) sprintf ("Hello World");
i) and ii)
i), ii) and iii)
i), ii), iii) and iv)
i), ii) and iv)
13. What will be the output of the following PHP code? <?php $color = "maroon"; $var = $color[2]; echo "$var"; ?>
a
Error
$var
R
14. What will be the output of the following PHP code? <?php $score = 1234; $scoreboard = (array) $score; echo $scoreboard[0]; ?>
1
Error
1234
2
15. What will be the output of the following PHP code? <?php $total = "25 students"; $more = 10; $total = $total + $more; echo "$total"; ?>
Error
35 students
35
25 students
16. Which of the below statements is equivalent to $add += $add?
$add = $add
$add = $add +$add
$add = $add + 1
$add = $add + $add + 1
17. Which statement will output $x on the screen?
echo “$x”;
echo “$$x”;
echo “/$x”;
echo “$x;”;
18. Which statement will output $x on the screen?
echo “$x”;
echo “$$x”;
echo “/$x”;
echo “$x;”;
19. What will be the output of the following PHP code? <?php function track() { static $count = 0; $count++; echo $count; } track(); track(); track(); ?>
123
111
000
011
20. What will be the output of the following PHP code? <?php $a = "clue"; $a .= "get"; echo "$a"; ?>
get
true
false
clueget
21. What will be the output of the following PHP code? <?php $a = 5; $b = 5; echo ($a === $b); ?>
5 === 5
Error
1
False
22. Which of the below symbols is a newline character?
/n
/r
23. Which of the conditional statements is/are supported by PHP? i) if statements ii) if-else statements iii) if-elseif statements iv) switch statements
Only i)
i), ii) and iv)
ii), iii) and iv)
i), ii), iii) and iv)
24. What will be the output of the following PHP code? <?php $team = "arsenal"; switch ($team) { case "manu": echo "I love man u"; case "arsenal": echo "I love arsenal"; case "manc": echo "I love manc"; } ?>
I love arsenal
Error
I love arsenalI love manc
I love arsenalI love mancI love manu
25. What will be the output of the following PHP code? <?php $user = array("Ashley", "Bale", "Shrek", "Blank"); for ($x=0; $x < count($user); $x++) { if ($user[$x] == "Shrek") continue; printf ($user[$x]); } ?>
AshleyBale
AshleyBaleBlank
ShrekBlank
Shrek
26. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
12
1
Error
5
27. What will be the value of $a and $b after the function call in the following PHP code? <?php function doSomething( &$arg ) { $return = $arg; $arg += 1; return $return; } $a = 3; $b = doSomething( $a ); ?>
a is 3 and b is 4
a is 4 and b is 3
Both are 3
Both are 4
28. Who is the father of PHP?
Rasmus Lerdorf
Willam Makepiece
Drek Kolkevi
List Barely
Submit