Practice high-yield Programming & Software Development MCQs on Basic Php — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does PHP stand for? 1. Personal Home Page 2. Hypertext Preprocessor 3. Pretext Hypertext Processor 4. Preprocessor Home Page
Correct Answer: Option D — Both 1 and 2
Detailed Academic Explanation:
PHP previously stood for Personal Home Page now stands for Hypertext Preprocessor.
💡Key Conceptual Anchor:Basic Php
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is/are a PHP code editor? 1. Notepad 2. Notepad++ 3. Adobe Dreamweaver 4. PDT
Correct Answer: Option B — All of the mentioned
Detailed Academic Explanation:
Any of the above editors can be used to type php code and run it.
💡Key Conceptual Anchor:Basic Php
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following must be installed on your computer so as to run PHP script? 1. Adobe Dreamweaver 2. PHP 3. Apache 4. IIS
Correct Answer: Option D — 2, 3 and 4
Detailed Academic Explanation:
To run PHP code you need to have PHP and a web server, both IIS and Apache are web servers.You can choose either one according to your platform.
💡Key Conceptual Anchor:Basic Php
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which version of PHP introduced Try/catch Exception?
Correct Answer: Option B — PHP 5
Detailed Academic Explanation:
Version 5 added support for Exception Handling.
💡Key Conceptual Anchor:Basic Php
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
We can use _________ to comment a single line? 1. /? 2. // 3. # 4. /* */
Correct Answer: Option C — 2, 3 and 4
Detailed Academic Explanation:
/* */ can also be use to comment just a single line although it is used for paragraphs. // and # are used only for single line comment.
💡Key Conceptual Anchor:Basic Php
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following php statement/statements will store 111 in variable num? 1. int $num = 111; 2. int mum = 111; 3. $num = 111; 4. 111 = $num;
Correct Answer: Option C — Only 3
Detailed Academic Explanation:
You need not specify the datatype in php.
💡Key Conceptual Anchor:Basic Php
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following php code? <?php $num = 1 ; $num1 = 2 ; print $num . "+" . $num1; ?>
Correct Answer: Option B — 1+2
Detailed Academic Explanation:
.(dot) is used to combine two parts of the statement. Example ( $num . “Hello World” ) will output 1Hello World.
💡Key Conceptual Anchor:Basic Php
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of following variables can be assigned a value to it? 1. $3hello 2. $_hello 3. $this 4. $This
Correct Answer: Option D — 2 and 4
Detailed Academic Explanation:
A variable can’t start with a number. Also $this is a special variable that can’t be assigned, but $This can be assigned.
💡Key Conceptual Anchor:Basic Php
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code? <?php $foo = 'Bob' ; $bar = & $foo; $bar = "My name is $bar" ; echo $bar; echo $foo; ?>
Correct Answer: Option C — My name is BobMy name is Bob
Detailed Academic Explanation:
The $bar = &$foo; line will reference $foo via $bar.
💡Key Conceptual Anchor:Basic Php
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following PHP statements will output Hello World on the screen? 1. echo (“Hello World”); 2. print (“Hello World”); 3. printf (“Hello World”); 4. sprintf (“Hello World”);
Correct Answer: Option B — 1, 2 and 3
Detailed Academic Explanation:
echo(), print() and printf() all three can be used to output a statement onto the screen. The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser.
💡Key Conceptual Anchor:Basic Php
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $color = "maroon" ; $var = $color [ 2 ] ; echo "$var" ; ?>
Correct Answer: Option D — r
Detailed Academic Explanation:
PHP treats strings in the same fashion as arrays, allowing for specific characters to be accessed via array offset notation.
💡Key Conceptual Anchor:Basic Php
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $score = 1234 ; $scoreboard = (array) $score; echo $scoreboard [ 0 ] ; ?>
Correct Answer: Option C — 1234
Detailed Academic Explanation:
The (array) is a cast operator which is used for converting values from other data types to array.
💡Key Conceptual Anchor:Basic Php
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $total = "25 students" ; $more = 10 ; $total = $total + $more; echo "$total" ; ?>
Correct Answer: Option C — 35
Detailed Academic Explanation:
The integer value at the beginning of the original $total string is used in the calculation. However if it begins with anything but a numerical value, the value will be 0.
💡Key Conceptual Anchor:Basic Php
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the below statements is equivalent to $add += $add ?
Correct Answer: Option B — $add = $add +$add
Detailed Academic Explanation:
a += b is an addition assignment whose outcome is a = a + b. Same can be done with subtraction,multiplication,division etc.
💡Key Conceptual Anchor:Basic Php
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which statement will output $x on the screen?
Correct Answer: Option A — echo “\$x”
Detailed Academic Explanation:
A backslash is used so that the dollar sign is treated as a normal string character rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as escape character.
💡Key Conceptual Anchor:Basic Php
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code? <?php function track () { static $count = 0 ; $count ++ ; echo $count; } track () ; track () ; track () ; ?>
Correct Answer: Option A — 123
Detailed Academic Explanation:
Because $count is static, it retains its previous value each time the function is executed.
💡Key Conceptual Anchor:Basic Php
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $a = "clue" ; $a .= "get" ; echo "$a" ; ?>
Correct Answer: Option D — clueget
Detailed Academic Explanation:
.= is a concatenation-assignment. $a equals its current value concatenated with “get”.
💡Key Conceptual Anchor:Basic Php
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $a = 5 ; $b = 5 ; span class = "sys-fun" >echo ( $a === $b ) ; ?>
Correct Answer: Option C — 1
Detailed Academic Explanation:
=== operator returns 1 if $a and $b are equivalent and $a and $b have the same type.
💡Key Conceptual Anchor:Basic Php
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the below symbols is a newline character?
Correct Answer: Option B — \n
Detailed Academic Explanation:
PHP treats \n as newline character.
💡Key Conceptual Anchor:Basic Php
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php $num = 10 ; echo 'What is her age? \n She is $num years old' ; ?>
Correct Answer: Option A — What is her age? n She is $num years old
Detailed Academic Explanation:
When a string is enclosed within single quotes both variables and escape sequences will not be interpreted when the string is parsed.
💡Key Conceptual Anchor:Basic Php
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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" ; } ?>
Correct Answer: Option C — I love arsenalI love manc
Detailed Academic Explanation:
If a break statement isn’t present, all subsequent case blocks will execute until a break statement is located.
💡Key Conceptual Anchor:Basic Php
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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 ]) ; } ?>
Correct Answer: Option B — AshleyBaleBlank
Detailed Academic Explanation:
The continue statement causes execution of the current loop iteration to end and commence at the beginning of the next iteration.
💡Key Conceptual Anchor:Basic Php
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
Correct Answer: Option D — 5
Detailed Academic Explanation:
?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .
💡Key Conceptual Anchor:Basic Php
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the value of $a and $b after the function call? <?php function doSomething ( & $arg ) { $return = $arg; $arg += 1 ; return $return; } $a = 3 ; $b = doSomething ( $a ) ; ?>
Correct Answer: Option B — a is 4 and b is 3
Detailed Academic Explanation:
$a is 4 and $b is 3. The former because $arg is passed by reference, the latter because the return value of the function is a copy of the initial value of the argument.
💡Key Conceptual Anchor:Basic Php
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
PHP files have a default file extension of_______.
Correct Answer: Option C — .php
Detailed Academic Explanation:
.php is the correct answer to “PHP files have a default file extension of_______.”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the conditional statements is/are supported by PHP? 1. if statements 2. if-else statements 3. if-elseif statements 4. switch statements
Correct Answer: Option D — All of the mentioned.
Detailed Academic Explanation:
All of the mentioned. is the correct answer to “Which of the conditional statements is/are supported by PHP? 1. if statements 2. if-else statements 3. if-elseif statements 4. switch statements”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the looping statements is/are supported by PHP? 1. for loop 2. while loop 3. do-while loop 4. foreach loop
Correct Answer: Option C — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “Which of the looping statements is/are supported by PHP? 1. for loop 2. while loop 3. do-while loop 4. foreach loop”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Who is the father of PHP?
Correct Answer: Option A — Rasmus Lerdorf
Detailed Academic Explanation:
Rasmus Lerdorf is the correct answer to “Who is the father of PHP”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How does the identity operator === compare two values?
Correct Answer: Option A — It converts them to a common compatible data type and then compares the resulting values
Detailed Academic Explanation:
It converts them to a common compatible data type and then compares the resulting values is the correct answer to “How does the identity operator === compare two values”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Under what circumstance is it impossible to assign a default value to a parameter while declaring a function?
Correct Answer: Option C — When the parameter is being declared as passed by reference
Detailed Academic Explanation:
When the parameter is being declared as passed by reference is the correct answer to “Under what circumstance is it impossible to assign a default value to a parameter while declaring a function”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Variables always start with a ........ in PHP
Correct Answer: Option C — Dollar-sign
Detailed Academic Explanation:
Dollar-sign is the correct answer to “Variables always start with a ........ in PHP”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
PHP is an open source software.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “PHP is an open source software.”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not valid PHP code?
Correct Answer: Option D — $10_somethings
Detailed Academic Explanation:
$10_somethings is the correct answer to “Which of the following is not valid PHP code”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
PHP runs on different platforms (Windows, Linux, Unix, etc.)
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “PHP runs on different platforms (Windows, Linux, Unix, etc.)”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
You can test the type of any variable with the ..... function.
Correct Answer: Option C — gettype()
Detailed Academic Explanation:
gettype() is the correct answer to “You can test the type of any variable with the ..... function.”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Assigning the empty string (like ' ') to a variable automatically renders it empty.
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “Assigning the empty string (like ' ') to a variable automatically renders it empty.”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If you echo a Boolean variable, the value FALSE displays as a .... and the value TRUE echoes as a .....
Correct Answer: Option D — blank string, 1
Detailed Academic Explanation:
blank string, 1 is the correct answer to “If you echo a Boolean variable, the value FALSE displays as a .... and the value TRUE echoes as a .....”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When a simple data type is casted to an array, an array is created with the original value in the first element.
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “When a simple data type is casted to an array, an array is created with the original value in the first element.”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
String values must be enclosed in ......
Correct Answer: Option C — both A and B
Detailed Academic Explanation:
both A and B is the correct answer to “String values must be enclosed in ......”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
PHP does not support numbers written in hexadecimal, octal or scientific notation.
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “PHP does not support numbers written in hexadecimal, octal or scientific notation.”. This question is standard in competitive examination syllabi for Basic Php.
💡Key Conceptual Anchor:Basic Php
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.