Sample questions
Question 1Medium
- PHP: hypertext preprocessor
- professional home page.
- Pure home page.
- None of the above.
Answer: A. PHP: hypertext preprocessor
Explanation
PHP is a scripted programming language that can be used to create websites. Short for "PHP: Hypertext Preprocessor" (the initials actually come from the earliest version of the program, which was called "Personal Home Page Tools"), it is an open-source, reflective programming language used mainly for developing server-side applications and dynamic web content, and more recently, a broader range of software applications.
Step-by-step solution
- The question asks what PHP stands for.
- PHP is a server-side scripting language used for dynamic web content.
- Its name stands for PHP: Hypertext Preprocessor, which is option A.
- The correct answer is option A, PHP: hypertext preprocessor.
Why the other options are wrong
- B. Professional home page is not the name; the name is Hypertext Preprocessor.
- C. Pure home page is not the name of PHP.
- D. Option A is the correct expansion, so none of the above is wrong.
Tip: Remember PHP as PHP: Hypertext Preprocessor.
Question 2Medium
How do you write "Hello World" in PHP?
"Hello World";echo "Hello World";Document.Write("Hello World");- None of these
Answer: B. echo "Hello World";
Explanation
The echo () function is used to output the given argument. It can output all types of data and multiple outputs can be made with only one echo () command.
Step-by-step solution
- The question asks for the PHP statement that prints Hello World.
- The echo statement outputs its argument, so echo followed by the quoted text prints it.
- Option B, echo followed by the quoted text and a semicolon, is the answer.
Why the other options are wrong
- A. A bare string on its own is not printed, because there is no echo.
- C. Document.Write is JavaScript, not PHP.
- D. Option B is valid PHP, so none of these is wrong.
Tip: In PHP, use echo to print text, and end the statement with a semicolon.
Question 3Medium
How the PHP script starts and ends?
- starts with <?html and ends with ?>
- starts with <?php and ends with ?>
- starts with <php> and ends with</php>
- All of the above
Answer: B. starts with <?php and ends with ?>
Explanation
php script starts with < ?php tag and ends with? > tag.
e.g
<html>
<body>
< ?php
echo "My first PHP script!";
?>
</body>
</html>
Step-by-step solution
- PHP code sits between an opening tag and a closing tag.
- The opening tag is
<?php and the closing tag is ?>. - So option B is the answer.
Why the other options are wrong
- A. The opening tag is
<?php, not <?html. - C. PHP tags are
<?php and ?>, not <php> tags. - D. Options A and C are wrong, so All of the above is wrong.
Tip: Open PHP code with <?php and close it with ?>.
Question 4Medium
Which of the following is not valid PHP code?
- $_10
- ${MyVar}
- &$something
- $10_somethings
Answer: D. $10_somethings
Explanation
PHP variables always start with a dollar sign and are a sequence of characters and numbers within the Latin alphabet, plus the underscore character.
${'MyVar'} is a valid variable name that simply uses a slightly less common naming convention, while &$something is a reference to the $something variable.
Variables, however cannot start with numbers, making $10_somethings invalid and Answer D correct.
Step-by-step solution
- A PHP variable starts with a dollar sign, then a letter or underscore, then letters, digits or underscores.
$_10 is valid because the name starts with an underscore.${MyVar} is valid because braces can wrap the name, and &$something is a valid reference.$10_somethings starts with a digit after the dollar sign, so it is invalid; the correct answer is option D.
Why the other options are wrong
- A. This is valid because an underscore can start a variable name.
- B. This is valid because braces can wrap a variable name.
- C. This is valid as a reference, for example in an assignment.
Tip: A variable name cannot start with a digit right after the dollar sign.
Question 5Medium
With register_globals enabled, which of the following practices is particularly important?
- Initialize all variables
- Filter all foreign data.
- Escape all data used in SQL statements.
- Escape all data prior to output.
Answer: A. Initialize all variables
Explanation
Answer A is correct. Answers B, C, and D are incorrect because these practices are not dependent on whether register_globals is enabled
Step-by-step solution
- The question asks which practice matters most when register_globals is enabled.
- The source explanation says the other three practices do not depend on register_globals.
- Initialising all variables is the practice tied to register_globals.
- The correct answer is option A, Initialize all variables.
Why the other options are wrong
- B. Filtering foreign data is needed whether or not register_globals is on.
- C. Escaping data in SQL statements does not depend on register_globals.
- D. Escaping data before output does not depend on register_globals.
Tip: Ask whether a practice depends on the setting in the question; keep only the one that does.
Question 6Medium
PHP supports explicit type definition in variable declaration.
- True
- False
Answer: B. False
Explanation
PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which the variable is used.
That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, it becomes an integer.
Step-by-step solution
- PHP does not require or support declaring a variable's type.
- A variable takes the type of the value assigned to it, and that type can change when a new value is assigned.
- So the statement is False.
Why the other options are wrong
- A. True is wrong, because PHP has no explicit type declaration for variables.
Tip: PHP is dynamically typed, so the type comes from the value.
Question 7Medium
what do you mean by conditional statements?
- It allow a program to execute different pieces of code, or none at all, depending on some condition.
- It support the repeated execution of particular code.
- These statements are executed compulsory.
- None of these.
Answer: A. It allow a program to execute different pieces of code, or none at all, depending on some condition.
Explanation
Conditional statements, such as if/else and switch, allow a program to execute different pieces of code, or none at all, depending on some condition.
Step-by-step solution
- Conditional statements let programs choose actions based on true/false checks.
- They run specific code when a condition is met, like if/else or switch cases.
- This lets the program adapt its behavior depending on input or state.
- Option A matches this definition exactly.
- Other options describe loops or mandatory execution, not conditions.
- Final answer: It allow a program to execute different pieces of code, or none at all, depending on some condition.
Why the other options are wrong
- B. Repeated execution describes loops, not conditional statements.
- C. Compulsory execution is the opposite of a conditional statement, which may run or skip code.
- D. None is wrong because conditional statements do let code run or skip depending on a condition.
Tip: Remember: if/else and switch are examples of conditional logic that change program behavior based on input.
Question 8Medium
____allowing you to branch the execution of the scripts based on input and easily handle repetitive task.
- Control structure.
- function
- array
- none of these.
Answer: A. Control structure.
Explanation
control structure allowing you to branch the execution of the scripts based on input and easily handle repetitive task.
There are two types of control structure in php:
1> conditional statements
2> control loops
Step-by-step solution
- Control structures let you make decisions in code using conditions.
- They also help repeat actions with loops, making scripts flexible.
- Conditional statements like if-else are examples of control structures.
- Loops such as for and while show how control structures handle repetition.
- Therefore, the correct term is control structure.
- Final answer: A (Control structure.).
Why the other options are wrong
- B. A function groups reusable code but does not branch on input or handle repeated tasks by itself.
- C. An array stores a collection of values; it does not branch the execution of a script.
- D. None of these is wrong because control structure fits the description.
Tip: Remember: Control structures = decisions + loops.
Question 9Medium
what is difference between $message and $$message in php?
- $message is a variable with a fixed name. $$message is a variable whose name is stored in $message.
- $$message is a variable with a fixed name. $message is a variable whose name is stored in $$message.
- Both are same.
- None of these
Answer: A. $message is a variable with a fixed name. $$message is a variable whose name is stored in $message.
Explanation
$message is a variable with a fixed name. $$message is a variable whose name is stored in $message. If $message contains "var", $$message is the same as $var.
Step-by-step solution
- $message is a normal variable with a fixed name.
- $$message is a variable variable, its name comes from the value of $message.
- If $message has value 'var', $$message refers to $var.
- So $message is fixed, $$message depends on $message.
- Final answer: $message is a variable with a fixed name. $$message is a variable whose name is stored in $message.
Why the other options are wrong
- B. It is the other way round; $message is fixed, and $$message uses the name stored in $message.
- C. Both are not same; $$message uses the value of $message as a variable name.
- D. None is wrong because option A states the difference correctly.
Tip: Remember: $$message uses the value of $message as its name.
Question 10Medium
what is the difference between include() and require()?
- are different how they handle failure
- both are same in every aspects
include() produced a Fatal Error while require results in a Warning- None of the Above
Answer: A. are different how they handle failure
Explanation
In PHP, you can insert the content of one PHP file into another PHP file before the server executes it. The include and require statements are used to insert useful codes written in other files, in the flow of execution.
Include and require are identical, except upon failure:
1. require will produce a fatal error (E_COMPILE_ERROR) and stop the script
2. include will only produce a warning (E_WARNING) and the script will continue
Step-by-step solution
- Both include and require insert the content of another file into the script.
- The explanation says they are identical except on failure.
- Require stops with a fatal error, while include gives a warning and carries on, so option A is the answer.
Why the other options are wrong
- B. They differ when the file is missing, so they are not the same in every aspect.
- C. This is reversed: include gives a warning and require gives a fatal error.
- D. Option A is correct, so None of the Above is wrong.
Tip: Use require for files the script cannot run without, and include for optional files.
Practise all 20 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →