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.

No cookies to display.

PHP MCQ

PHP MCQ – Multiple Choice Questions and Answers – Basics – Part 2

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

 

2. Which is a newline character?

A /r

B /n

C \n

D \r

 

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

 

4. 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 12

B 3

C 1+2

D Error

 

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

 

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;

 

7. Which of the looping statements are approved by PHP?

A for loop

B while loop

C do-while loop

D foreach loop

 

8. Which is the correct way of declaring a variable in PHP?

A $2var

B $_var

C $this

D $This

 

9. What is the result of the following PHP code?
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
$name = "Thomas";
$var = $name[3];
echo "$var";
?>
<?php $name = "Thomas"; $var = $name[3]; echo "$var"; ?>
<?php
    $name = "Thomas";
    $var = $name[3];
    echo "$var";
?>

A o

B m

C $var

D Error

 

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

mcq

Leave a Reply

Your email address will not be published. Required fields are marked *