PHP MCQ – Multiple Choice Questions and Answers – Basics – Part 3
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “PHP basic”.
1. Which of the following statement will output $a on the screen?
A echo "\$a";
B echo "$$a";
C echo "/$a";
D echo "$a;";
2. What is the result of the following PHP code?
<?php
$total = "10 persons";
$plus = 5;
$total = $total + $plus;
echo "$total";
?>
A 15
B Error
C 15 persons
D 10 persons
3. If $x = 10 what will be returned when ($x == 10) ? 2 : 4 is executed?
A 10
B 2
C 4
D Error
4. What is the result of the following PHP code?
<?php
$name = "Emily";
echo 'What is her name? \n She is $name';
?>
A
What is her name? \n She is $name
B
What is her name? She is $name
C
What is her name? She is Emily
D
What is her name? She is Emily
5. What is the result of the following PHP code?
<?php
$name = "Alex";
switch ($name)
{
case "Emily":
echo "Hello Emily. Welcome to StackHowTo!";
case "Alex":
echo "Hello Alex. Welcome to StackHowTo!";
case "Bob":
echo "Hello Bob. Welcome to StackHowTo!";
}
?>
A Hello Bob. Welcome to StackHowTo!
B Hello Alex. Welcome to StackHowTo!
C Hello Alex. Welcome to StackHowTo!Hello Bob. Welcome to StackHowTo!
D Error
6. Which statements will output “Welcome to StackHowTo!” on the screen?
A echo(“Welcome to StackHowTo!”);
B print(“Welcome to StackHowTo!”);
C printf(“Welcome to StackHowTo!”);
D sprintf(“Welcome to StackHowTo!”);
7. What is the result of the following PHP code?
<?php
$n = 1234;
$arr = (array) $n;
echo $arr[0];
?>
A 2
B 1
C Error
D 1234
8. What is the result of the following PHP code?
<?php
$tmp = 'Alex';
$name = &$tmp;
$name = "My name is $name";
echo $name;
echo $tmp;
?>
A ERROR
B My name is Alex Alex
C My name is AlexMy name is Alex
D My name is Alex
9. What is the result of the following PHP code?
<?php
$str = "Stack";
$str .= "How";
$str .= "To";
echo "$str";
?>
A Stack
B How
C To
D StackHowTo
10. What is the result of the following PHP code?
<?php
function countDown()
{
static $count = 10;
$count--;
echo $count;
}
countDown();
countDown();
countDown();
?>
A 1098
B 987
C 789
D 101010






