We use cookies to enhance your browsing experience, serve personalized ads or content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies.
Customize Consent Preferences
We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ...
Always Active
Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.
No cookies to display.
Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.
No cookies to display.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.
No cookies to display.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
No cookies to display.
Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “PHP basic”.
1. What is the result of the following PHP code?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
$a = 1;
$b = 2;
print$a ."+". $b;
?>
<?php
$a = 1;
$b = 2;
print $a ."+". $b;
?>
<?php
$a = 1;
$b = 2;
print $a ."+". $b;
?>
A 1.+.2
B 1+2
C 3
D Error
B
.(dot) is used to concatenate two parts of the statement.
2. Which is a newline character?
A /r
B /n
C \n
D \r
C
PHP deal with \n as a newline character.
How to add a new line within echo in PHP?Line breaks are not automatically generated when outputting using echo(): <?php echo('A'); echo('B'); echo('C'); ?> Output: ABC Instead, it is necessary to set them manually.…Read More
3. What is the result of the following PHP code?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
$a = 1;
$b = 2;
echo($a !== $b);
?>
<?php
$a = 1;
$b = 2;
echo ($a !== $b);
?>
<?php
$a = 1;
$b = 2;
echo ($a !== $b);
?>
A 1 !== 2
B Error
C 1
D False
C
!== operator returns 1 if $a and $b are different and $a and $b have the same type.
The numbers within the double quotes are examined as integers and not string, so the value 3 is displayed and not 1+2.
5. Which of the conditional statements below are supported by PHP?
A if statements
B if-else statements
C if-elseif statements
D switch statements
A, B, C, D
All statements are supported by PHP and all are used to determine different conditions during a program and take decisions on the basis of whether these conditions evaluate to true or false.
6. Which of the following PHP declarations will store 5 in nbr?
A
5 = $nbr;
5 = $nbr;
B
$nbr = 5;
$nbr = 5;
C
int nbr = 5;
int nbr = 5;
D
int$nbr = 5;
int $nbr = 5;
B
You don’t need to indicate the datatype in PHP.
How to Define a Variable in PHPVariables are “containers” that can store specified or determined values, similar to variables in mathematics. These values can be of different types, so-called data types.…Read More
7. Which of the looping statements are approved by PHP?
A for loop
B while loop
C do-while loop
D foreach loop
A, B, C, D
All the loops above are supported in PHP as they can repeat the same block of code a given number of times, or until a particular condition is met.
8. Which is the correct way of declaring a variable in PHP?
A $2var
B $_var
C $this
D $This
B, D
A variable in PHP can’t start with a number, also $this is mostly used as reference to properties of a class so we can’t use $this as a user define variable name.
How to Define a Variable in PHPVariables are “containers” that can store specified or determined values, similar to variables in mathematics. These values can be of different types, so-called data types.…Read More
PHP deals with strings in the same way as arrays, allowing for specific characters to be accessed using array offset notation. In an array, index always starts from 0. So in the line
$var = $name[3];
$var = $name[3]; if we count from start ‘m’ comes at index 3. So the output will be m.
10. Which of the following statements is equivalent to
$nbr += $nbr
$nbr += $nbr?
A
$nbr = $nbr
$nbr = $nbr
B
$nbr = $nbr + $nbr
$nbr = $nbr + $nbr
C
$nbr = $nbr + 1
$nbr = $nbr + 1
D
$nbr = $nbr + $nbr + 1
$nbr = $nbr + $nbr + 1
B
a += b is an addition assignment whose result is a = a + b. Identical to subtraction, multiplication, division, etc.
MCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More