MCQs | PHP/PHP MCQ Sample Test,Sample questions

Question:
Which of the following web servers are required to run the PHP script?

1.Apache and PHP

2.IIS

3.XAMPP

4.Any of the mentioned


Question:
How to define a function in PHP?

1.functionName(parameters) {function body}

2.function {function body}

3.function functionName(parameters) {function body}

4.data type functionName(parameters) {function body}


Question:
What will be the output of the following PHP code snippet?

<?php
    $url = "phpmcq@sanfoundry.com";
    echo ltrim(strstr($url, "@"),"@");
?>

1.phpmcq@sanfoundry.com

2.php@sanfoundry.com

3.phpmcq@

4.sanfoundry.com


Question:
What will be the output of the following PHP code?

<?php
$x = 10;
$y = 20;
if ($x > $y && 1||1)
    print "1000 PHP MCQ" ;
else
    print "Welcome to Sanfoundry";
?>

1.no output

2.Welcome to Sanfoundry

3.1000 PHP MCQ

4.error


Question:
What will be the output of the following PHP code?

<?php
function constant()
{
    define("GREETING", "Welcome to Sanfoundry",true);
    echo greeting;
}
?>

1.GREETING

2.Welcome to Sanfoundry

3.ERROR

4.greeting


Question:
What will be the output of the following PHP program?

<?php
    function multi($num)
    {
        if ($num == 3)
            echo "I Wonder";
        if ($num == 7)
            echo "Which One";
        if ($num == 8)
            echo "Is The";
        if ($num == 19)
            echo "Correct Answer";
    }
    $can = stripos("I love php, I love php too!","PHP");
    multi($can);
?>

1.Correct Answer

2.Is The

3.I Wonder

4.Which One


Question:
Which of the following is the default file extension of PHP files?

1..php

2..ph

3..xml

4..html


Question:
Which of the looping statements is/are supported by PHP?

i) for loop
ii) while loop
iii) do-while loop
iv) foreach loop

1.Only iv)

2.i) and ii)

3.i), ii) and iii)

4.i), ii), iii) and iv)


Question:
Which PHP function displays the web page’s most recent modification date?

1.getlastmod()

2.get_last_mod()

3.lastmod()

4. last_mod()


Question:
Which PHP function displays the web page’s most recent modification date?
a)

1.getlastmod()

2.get_last_mod()

3.lastmod()

4. last_mod()


Question:
. In the following PHP program, what is/are the properties?

<?php
    class Example 
    {
        public $name;
        function Sample()
        {
            echo "Learn PHP @ Sanfoundry";
        }
    } 
?>

1. function sample()

2.echo “This is an example”;

3.public $name;

4.class Example


Question:
A function in PHP which starts with __ (double underscore) is known as __________

1.Default Function

2.User Defined Function

3. Inbuilt Function

4.Magic Function


Question:
If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?

1.1

2.5

3.12

4.Error


Question:
The developers of PHP deprecated the safe mode feature as of which PHP version?

1.PHP 5.3.1

2. PHP 5.3.0

3.PHP 5.1.0

4.PHP 5.2.0


Question:
What does PDO stand for?

1.PHP Database Orientation

2.PHP Data Orientation

3.PHP Data Object

4.PHP Database Objec


Question:
What does PHP stand for?

1.PHP stands for Preprocessor Home Page

2.PHP stands for Pretext Hypertext Processor

3.PHP stands for Hypertext Preprocessor

4.PHP stands for Personal Hyper Processor


Question:
What is PHP?

1.PHP is an open-source programming language

2.PHP is used to develop dynamic and interactive websites

3.PHP is a server-side scripting language

4.All of the mentioned


Question:
What will be the output of the following PHP code?

<?php
$x = 4;
$y = 3
$z = 1;
$z = $z + $x + $y;
echo "$z";
?>

1.15

2.8

3.1

4.$z


Question:
What will be the output of the following PHP code?

<?php
$x = 5;
$y = 10;
function fun()
{
    $y = $GLOBALS['x'] + $GLOBALS['y'];
} 
fun();
echo $y;
?>

1.5

2.10

3.15

4.Error


Question:
What will be the output of the following PHP code?

<?php
define("GREETING", "PHP is a scripting language");
echo $GREETING;
?>

1.$GREETING

2.no output

3.PHP is a scripting language

4.GREETING


Question:
What will be the output of the following PHP program?

<?php
$a = "$winner";
$b = "/$looser";
echo $a,$b;
?>

1. /

2.$looser

3.$looser/

4.$winner/$looser


Question:
What will be the output of the following PHP program?

<?php
$a = 100;
if ($a > 10)
    printf("PHP Quiz");
else if ($a > 20)
    printf("PHP MCQ");
else if($a > 30)
    printf("PHP Program");
?>

1.PHP Quiz PHP MCQ PHP Program

2.PHP Quiz

3.PHP MCQ

4.No output


Question:
What will be the output of the following PHP program?

<?php
$fruits = array ("apple", "orange", array ("pear", "mango"),"banana");
echo (count($fruits, 1));
?>

1.6

2.5

3.4

4.3


Question:
What will be the output of the following PHP program?

<?php
$i = 5;
while (--$i > 0 && ++$i)
{   
    print $i;
}
?>

1. 555555555…infinitely

2.54321

3.Error

4.5


Question:
What will be the output of the following PHP program?

<?php
$mcq = 1;
switch(print $mcq)
{
case 2:
    print "HTML";
    break;
case 1:
    print "CSS";
    break;
default:
    print "JavaScript";
}
?>

1.error

2.1HTML

3.1JavaScript

4.1CSS


Question:
What will be the output of the following PHP program?

<?php
$php = array("Array", "Function", "Strings", "File");
echo pos($php);
?>

1.Function

2.File

3.Strings

4.Array


Question:
What will be the output of the following PHP program?

<?php
$php = array("Array", "Function", "Strings", "File");
echo pos($php);
?>

1.Function

2.File

3.Strings

4.Array


Question:
What will be the output of the following PHP program?

<?php
define("VAR_NAME","test"); 
${VAR_NAME} = "value"; 
echo VAR_NAME;
echo ${VAR_NAME}; 
?>

1. testtest

2.testvalue

3.error, constant value cannot be changed

4. test


Question:
What will be the value of the variable $input in the following PHP program?

<?php
$input = "PHP<td>stands for</td>Hypertext<i>Preprocessor</i>!";
$input = strip_tags($input,"<i></i>");
echo $input;
?>

1.PHP stands for Hypertext <i>Preprocessor</i>!

2.PHP stands for Hypertext Preprocessor!

3.PHP <td>stands for</td> Hypertext <i>Preprocessor</i>!

4.PHP <td>stands for</td> Hypertext Preprocessor!


Question:
Which is the right way of declaring a variable in PHP?

1.$3hello

2. $_hello

3.$_hello

4.$this


Question:
Which of the following is the correct syntax to write a PHP code?

1.<?php ?>

2.< php >

3.< ? php ?>

4.<? ?>


Question:
Which of the following is the correct way to add a comment in PHP code?

1.#

2.//

3./* */

4.All of the mentioned


Question:
Which of the following PHP functions can be used for generating unique ids?

1.md5()

2.uniqueid()

3.mdid()

4.id()


Question:
Which of the following variables does PHP use to authenticate a user?

i) $_SERVER['PHP_AUTH_USER'].
ii) $_SERVER['PHP_AUTH_USERS'].
iii) $_SERVER['PHP_AUTH_PU'].
iv) $_SERVER['PHP_AUTH_PW'].

1. ii) and iv)

2. i) and iv)

3.ii) and iii)

4.i) and ii)


Question:
Which one of the following is the default PHP session name?

1.PHPSESSIONID

2.PHPIDSESS

3.PHPSESSID

4.PHPSESID


Question:
Which PHP statement will give output as $x on the screen?

1.echo “$x”;

2.echo “$$x”;

3.echo “/$x”;

4.echo “$x;”;


Question:
Which variable is used to collect form data sent with both the GET and POST methods?

1.$_BOTH

2.$REQUEST

3.$_REQUEST

4.$BOTH


Question:
Which version of PHP introduced the advanced concepts of OOP?

1.PHP 6

2.PHP 4

3.PHP 5

4.PHP 5.3


Question:
Who is the father of PHP?

1. Drek Kolkevi

2.Rasmus Lerdorf

3.Willam Makepiece

4.List Barely


More MCQS

  1. PHP Mcq Set 1
  2. PHP Mcq Set 2
  3. PHP Mcq Set 3
  4. PHP Mcq Set 4
  5. Current affairs mcq php
  6. Current affairs mcq php set 2
  7. Current affairs mcq php set 3
  8. PHP MCQ
  9. PHP MCQ– Basics
  10. PHP Mcq – Functions
  11. PHP Mcq Arrays
  12. PHP Mcq– Basics of Object-Oriented PHP
  13. PHP Mcq – Error Handling
  14. PHP Basics Mcq Questions
Search