0% found this document useful (0 votes)
236 views20 pages

PHP

Uploaded by

vermabhanu0298
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
236 views20 pages

PHP

Uploaded by

vermabhanu0298
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

1. What is PHP?

a) PHP is an open-source programming language


b) PHP is used to develop dynamic and interactive websites
c) PHP is a server-side scripting language
d) All of the mentioned

2. Who is the father of PHP?


a) Drek Kolkevi
b) Rasmus Lerdorf
c) Willam Makepiece
d) List Barely

3. What does PHP stand for?


a) PHP stands for Preprocessor Home Page
b) PHP stands for Pretext Hypertext Processor
c) PHP stands for Hypertext Preprocessor
d) PHP stands for Personal Hyper Processor

4. Which of the following is the correct syntax to write a PHP code?


a) <?php ?>
b) < php >
c) < ? php ?>
d) <? ?>

5. Which of the following is the correct way to add a comment in PHP code?
a) #
b) //
c) /* */
d) All of the mentioned

6. Which of the following is the default file extension of PHP files?


a) .php
b) .ph
c) .xml
d) .html

7. How to define a function in PHP?


a) functionName(parameters) {function body}
b) function {function body}
c) function functionName(parameters) {function body}
d) data type functionName(parameters) {function body}

8. 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";

?>

a) no output
b) Welcome to Sanfoundry
c) 1000 PHP MCQ
d) error
9. Which is the right way of declaring a variable in PHP?
a) $3hello
b) $_hello
c) $this
d) $5_Hello

10. What will be the output of the following PHP program?

<?php

$fruits = array ("apple", "orange", array ("pear", "mango"),"banana");

echo (count($fruits, 1));

?>

a) 6
b) 5
c) 4
d) 3

11. 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);

?>

a) Correct Answer
b) Is The
c) I Wonder
d) Which One

12. Which of the following PHP functions can be used for generating unique ids?
a) md5()
b) uniqueid()
c) mdid()
d) id()

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

<?php

class Example
{

public $name;

function Sample()

echo "Learn PHP @ Sanfoundry";

?>

a) function sample()
b) echo “This is an example”;
c) public $name;
d) class Example

14. What will be the output of the following PHP code?

<?php

define("GREETING", "PHP is a scripting language");

echo $GREETING;

?>

a) $GREETING
b) no output
c) PHP is a scripting language
d) GREETING

15. A function in PHP which starts with __ (double underscore) is known as __________
a) Default Function
b) User Defined Function
c) Inbuilt Function
d) Magic Function

16. How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions.
a) 10
b) 7
c) 8
d) 9

17. Which of the following web servers are required to run the PHP script?
a) Apache and PHP
b) IIS
c) XAMPP
d) Any of the mentioned

18. What will be the output of the following PHP code snippet?

<?php

$url = "[email protected]";

echo ltrim(strstr($url, "@"),"@");

?>a) [email protected]
b) [email protected]
c) phpmcq@
d) sanfoundry.com
19. Which of the following PHP functions can be used to get the current memory usage?
a) memory_get_usage()
b) memory_get_peak_usage()
c) get_peak_usage()
d) get_usage()

20. Which one of the following PHP function is used to determine a file’s last access time?
a) filetime()
b) fileatime()
c) fileltime()
d) filectime()

21. 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;

?>

a) 5
b) 10
c) 15
d) Error

22. PHP recognizes constructors by the name _________


a) function __construct()
b) function _construct()
c) classname()
d) _construct()

23. The developers of PHP deprecated the safe mode feature as of which PHP version?
a) PHP 5.3.1
b) PHP 5.3.0
c) PHP 5.1.0
d) PHP 5.2.0

24. 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;

?>

a) PHP stands for Hypertext <i>Preprocessor</i>!


b) PHP stands for Hypertext Preprocessor!
c) PHP <td>stands for</td> Hypertext <i>Preprocessor</i>!
d) PHP <td>stands for</td> Hypertext Preprocessor!
25. 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'].

a) ii) and iv)


b) i) and iv)
c) ii) and iii)
d) i) and ii)

26. What does PDO stand for?


a) PHP Database Orientation
b) PHP Data Orientation
c) PHP Data Object
d) PHP Database Object

27. 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");

?>

a)

PHP Quiz

PHP MCQ

PHP Program

b) PHP Quiz
c) No output
d) PHP MCQ

28. Which of the looping statements is/are supported by PHP?

i) for loop

ii) while loop

iii) do-while loop

iv) foreach loop

a) Only iv)
b) i) and ii)
c) i), ii) and iii)
d) i), ii), iii) and iv)
29. Which PHP statement will give output as $x on the screen?
a) echo “\$x”;
b) echo “$$x”;
c) echo “/$x”;
d) echo “$x;”;

30. Which version of PHP introduced the advanced concepts of OOP?


a) PHP 6
b) PHP 4
c) PHP 5
d) PHP 5.3

31. What will be the output of the following PHP code?

<?php

$x = 4;

$y = 3

$z = 1;

$z = $z + $x + $y;

echo "$z";

?>

a) 15
b) 8
c) 1
d) $z

32. What will be the output of the following PHP program?

<?php

$a = "$winner";

$b = "/$looser";

echo $a,$b;

?>

a) /
b) $looser
c) /$looser
d) $winner/$looser

33. Which one of the following is the default PHP session name?
a) PHPSESSIONID
b) PHPIDSESS
c) PHPSESSID
d) PHPSESID

34. 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";

?>

a) error
b) 1HTML
c) 1JavaScript
d) 1CSS

35. What will be the output of the following PHP program?

<?php

define("VAR_NAME","test");

${VAR_NAME} = "value";

echo VAR_NAME;

echo ${VAR_NAME};

?>

a) testtest
b) testvalue
c) error, constant value cannot be changed
d) test

36. Which PHP function displays the web page’s most recent modification date?
a) getlastmod()
b) get_last_mod()
c) lastmod()
d) last_mod()

37. What will be the output of the following PHP program?

<?php

$i = 5;

while (--$i > 0 && ++$i)

print $i;

?>

a) 555555555…infinitely
b) 54321
c) error
d) 5
38. What will be the output of the following PHP code?

<?php

function constant()

define("GREETING", "Welcome to Sanfoundry",true);

echo greeting;

?>

a) GREETING
b) Welcome to Sanfoundry
c) ERROR
d) greeting

39. Which variable is used to collect form data sent with both the GET and POST methods?
a) $_BOTH
b) $REQUEST
c) $_REQUEST
d) $BOTH

40. What will be the output of the following PHP program?

<?php

$php = array("Array", "Function", "Strings", "File");

echo pos($php);

?>

a) Function
b) File
c) Strings
d) Array

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


a) 1
b) 5
c) 12

1. Which one of the following databases has PHP supported almost since the beginning?
a) Oracle Database
b) SQL
c) SQL+
d) MySQL

2. The updated MySQL extension released with PHP 5 is typically referred to as _______________
a) MySQL
b) mysql
c) mysqli
d) mysqly

3. Which one of the following lines need to be uncommented or added in the php.ini file so as to enable mysqli
extension?
a) extension=php_mysqli.dll
b) extension=mysql.dll
c) extension=php_mysqli.dl
d) extension=mysqli.dl
4. In which version of PHP was MySQL Native Driver(also known as mysqlnd) introduced?
a) PHP 5.0
b) PHP 5.1
c) PHP 5.2
d) PHP 5.3

5. Which one of the following statements is used to create a table?


a) CREATE TABLE table_name (column_name column_type);
b) CREATE table_name (column_type column_name);
c) CREATE table_name (column_name column_type);
d) CREATE TABLE table_name (column_type column_name);

6. Which one of the following statements instantiates the mysqli class?


a) mysqli = new mysqli()
b) $mysqli = new mysqli()
c) $mysqli->new.mysqli()
d) mysqli->new.mysqli()

7.Which one of the following statements can be used to select the database?
a) $mysqli=select_db('databasename');
b) mysqli=select_db('databasename');
c) mysqli->select_db('databasename');
d) $mysqli->select_db('databasename');

8. Which one of the following methods can be used to diagnose and display information about a MySQL connection error?
a) connect_errno()
b) connect_error()
c) mysqli_connect_errno()
d) mysqli_connect_error()

9. Which method returns the error code generated from the execution of the last MySQL function?
a) errno()
b) errnumber()
c) errorno()
d) errornumber()

10. If there is no error, then what will the error() method return?
a) TRUE
b) FALSE
c) Empty String
d) 0

1. Which one of the following statements should be used to include a file?


a) #include ‘filename’;
b) include ‘filename’;
c) @include ‘filename’;
d) #include <filename>;

2. Which one of the following methods is responsible for sending the query to the database?
a) query()
b) send_query()
c) sendquery()
d) mysqli_query()

3. Which one of the following methods recuperates any memory consumed by a result set?
a) destroy()
b) mysqli_free_result()
c) alloc()
d) free()
4. Which of the methods are used to manage result sets using both associative and indexed arrays?
a) get_array() and get_row()
b) get_array() and get_column()
c) fetch_array() and fetch_row()
d) mysqli_fetch_array() and mysqli_fetch_row()

5. Which one of the following method is used to retrieve the number of rows affected by an INSERT, UPDATE, or DELETE
query?
a) num_rows()
b) affected_rows()
c) changed_rows()
d) mysqli_affected_rows()

6. Which version of MySQL introduced the prepared statements?


a) MySQL 4.0
b) MySQL 4.1
c) MySQL 4.2
d) MySQL 4.3

7. Which of the following methods is used to execute the statement after the parameters have been bound?
a) bind_param()
b) bind_result()
c) bound_param()
d) bound_result()

8. Which one of the following methods is used to recuperating prepared statements resources?
a) end()
b) finish()
c) mysqli_close()
d) close()

9. Which method retrieves each row from the prepared statement result and assigns the fields to the bound results?
a) get_row()
b) fetch_row()
c) fetch()
d) mysqli_fetch_row()

10. Which method rolls back the present transaction?


a) commit()
b) undo()
c) mysqli_rollback()
d) rollback()

3) Variable name in PHP starts with -

1. ! (Exclamation)

2. $ (Dollar)

3. & (Ampersand)

4. # (Hash)

4) Which of the following is the default file extension of PHP?

1. .php

2. .hphp

3. .xml

4. .html

5) Which of the following is not a variable scope in PHP?


1. Extern

2. Local

3. Static

4. Global

6) Which of the following is correct to add a comment in php?

1. & …… &

2. // ……

3. /* …… */

4. Both (b) and (c)

7) Which of the following is used to display the output in PHP?

1. echo

2. write

3. print

4. Both (a) and (c)

8) Which of the following is the use of strlen() function in PHP?

1. The strlen() function returns the type of string

2. The strlen() function returns the length of string

3. The strlen() function returns the value of string

4. The strlen() function returns both value and type of string

9) Which of the following is used for concatenation in PHP?

1. + (plus)

2. * (Asterisk)

3. . (dot)

4. append()

10) Which of the following starts with __ (double underscore) in PHP?

1. Inbuilt constants

2. User-defined constants

3. Magic constants

4. Default constants

11) Which of the following is the use of strpos() function in PHP?

1. The strpos() function is used to search for the spaces in a string

2. The strpos() function is used to search for a number in a string

3. The strpos() function is used to search for a character/text in a string

4. The strpos() function is used to search for a capitalize character in a string

12) What does PEAR stands for?

1. PHP extension and application repository

2. PHP enhancement and application reduce


3. PHP event and application repository

4. None of the above

13) Which of the following is the correct way to create a function in PHP?

1. Create myFunction()

2. New_function myFunction()

3. function myFunction()

4. None of the above

14) Which of the following PHP function is used to generate unique id?

1. id()

2. mdid()

3. uniqueid()

4. None of the above

15) Which of the following is the correct way of defining a variable in PHP?

1. $variable name = value;

2. $variable_name = value;

3. $variable_name = value

4. $variable name as value;

16) Which of the following is the correct use of the strcmp() function in PHP?

1. The strcmp() function is used to compare the strings excluding case

2. The strcmp() function is used to compare the uppercase strings

3. The strcmp() function is used to compare the lowercase strings

4. The strcmp() function is used to compare the strings including case

17) What is the use of fopen() function in PHP?

1. The fopen() function is used to open folders in PHP

2. The fopen() function is used to open remote server

3. The fopen() function is used to open files in PHP

4. None of the above

18) What is the use of isset() function in PHP?

1. The isset() function is used to check whether variable is set or not

2. The isset() function is used to check whether the variable is free or not

3. The isset() function is used to check whether the variable is string or not

4. None of the above

19) What is the use of sprintf() function in PHP?

1. The sprintf() function is used to print the output of program

2. The sprintf() function is used to send output to variable

3. Both of the above

4. None of the above


20) Which of the following is the correct way to open the file "sample.txt" as readable?

1. fopen("sample.txt", "r");

2. fopen("sample.txt", "r+");

3. fopen("sample.txt", "read");

4. fopen("sample.txt");

21) Which of the following function displays the information about PHP and its configuration?

1. php_info()

2. phpinfo()

3. info()

4. None of the above

22) Which of the following function is used to find files in PHP?

1. glob()

2. fold()

3. file()

4. None of the above

23) Which of the following function is used to set cookie in PHP?

1. createcookie()

2. makecookie()

3. setcookie()

4. None of the above

24) Which of the following function is used to get the ASCII value of a character in PHP?

1. val()

2. asc()

3. ascii()

4. chr()

25) Which of the following function is used to unset a variable in PHP?

1. delete()

2. unset()

3. unlink()

4. None of the above

26) Which of the following function is used to sort an array in descending order?

1. sort()

2. asrot()

3. dsort()

4. rsort()

27) Which of the following is/are the code editors in PHP?

1. Notepad++
2. Notepad

3. Adobe Dreamweaver

4. All of the above

28) Which of the following is used to end a statement in PHP?

1. . (dot)

2. ; (semicolon)

3. ! (exclamation)

4. / (slash)

29) Which of the following function in PHP can be used to test the type of any variable?

1. showtype()

2. gettype()

3. settype()

4. None of the above

30) String values in PHP must be enclosed within -

1. Double Quotes

2. Single Quotes

3. Both (a) and (b)

4. None of the above

31) Which of the following variable name is invalid?

1. $newVar

2. $new_Var

3. $new-var

4. All of the above

32) Which of the following is the correct way to create an array in PHP?

1. $season = array["summer" , "winter" , "spring" , "autumn"];

2. $season = array("summer" , "winter" , "spring" , "autumn");

3. $season = "summer" , "winter" , "spring" , "autumn";

4. All of the above

33) Which of the following is a built-in function in PHP that adds a value to the end of an array?

1. array_push()

2. inend_array()

3. into_array()

4. None of the above

34) Which of the following function in PHP returns a text in title case from a variable?

1. toUpper($var)

2. ucwords($var)

3. ucword($var)
4. All of the above

35) Which of the following is the correct way to print "Hello World" in PHP?

1. "Hello World";

2. write("Hello World");

3. echo "Hello World";

4. None of the above

36) Which of the following function is used to compress a string in PHP?

1. compress()

2. zip_compress()

3. gzcompress()

4. zip()

37) What does SPL stands for in PHP?

1. Standard PHP Library

2. Simple PHP Library

3. Simple PHP List

4. None of the above

38) Which of the following function converts a string to all uppercase?

1. upper()

2. uppercase()

3. struppercase()

4. strtoupper()

39) The function in PHP that can be used to concatenate array elements to form a single delimited string is -

1. implode()

2. concat()

3. explode()

4. concatenate()

40) Which PHP function determines the last access time of a file?

1. filetime()

2. fileatime()

3. filectime()

4. None of the above

41) Which PHP function is capable to read specific number of characters from a file?

1. filegets()

2. fget()

3. fgets()

4. None of the above


42) Which PHP function is used to find the position of the last occurrence of a substring inside another string?

1. strops()

2. strrpos()

3. strtr()

4. None of the above

43) What will be the output of the following program?

1. <?php

2. echo "Welcome" . "to" . "the" . "javaTpoint.com";

3. ?>

1. Welcome to the javaTpoint.com

2. Welcome, to, the, javaTpoint.com

3. com

4. Error

44) What will be the output of the following program?

1. <?php

2. echo "Welcome" , "to" , "the" , "javaTpoint.com";

3. ?>

1. Welcome to the javaTpoint.com

2. Welcome, to, the, javaTpoint.com

3. com

4. Error

45) What will be the output of the following program?

1. <?php

2. $var1 = "Hello";

3. $var2 = "World";

4. echo $var1, $var2;

5. ?>

1. HelloWorld

2. Hello, World

3. Hello World

4. None of the above

46) What will be the output of the following program?

1. <?php

2. $var1 = "Hello";

3. $var2 = "World";

4. echo "$var1$var2";

5. ?>
1. HelloWorld

2. "$var1$var2"

3. Hello World

4. None of the above

47) What will be the output of the following program?

1. <?php

2. $a;

3. if ($a)

4. {

5. echo "hi";

6. }

7. else

8. {

9. echo "How are you";

10. }

11. ?>

1. Hi How are you

2. How are you

3. Hi

4. None of the above

48) What will be the output of the following program?

1. <?php

2. $a = 0;

3. while ($a++)

4. {

5. echo "$a";

6. }

7. echo $a;

8. ?>

1. 0

2. 1

3. 01

4. None of the above

49) What will be the output of the following program?

1. <?php

2. echo ucwords("welcome to the javaTpoint.com");

3. ?>
1. Welcome to the javaTpoint.com

2. welcome to the javaTpoint.com

3. Welcome To The JavaTpoint.com

4. Welcome to the JavaTpoint.com

50) What will be the output of the following program?

1. <?php

2. $a = 15;

3. function show()

4. {

5. $a = 20;

6. echo "$a";

7. }

8. show();

9. echo "$a";

10. ?>

1. 2015

2. 2020

3. 1515

4. 0

51) What will be the output of the following program?

1. <?php

2. $x = 15;

3. $y = 20;

4. if($x < ++$x || $y < ++$y)

5. {

6. echo "Hello World";

7. }

8. else

9. {

10. echo "Hii everyone";

11. }

12. ?>

1. Hii everyone

2. Hello World

3. Hello World Hii everyone

4. None of the above


52) What will be the output of the following program?

1. <?php

2. echo lcfirst("Welcome To The JavaTpoint.com");

3. ?>

1. welcome To The JavaTpoint.com

2. Welcome To The JavaTpoint.com

3. Welcome To The javaTpoint.com

4. None of the above

53) What will be the output of the following program?

1. <?php

2. $a = "1";

3. switch($a)

4. {

5. case 1:

6. echo "Hello";

7. case 2:

8. echo "World";

9. default:

10. echo "This is javaTpoint.com";

11. }

12. ?>

1. HelloWorld

2. This is javaTpoint.com

3. Hello

4. HelloWorldThis is javaTpoint.com

54) What will be the output of the following program?

1. <?php

2. echo strtr("Walcoma to the juvuTpoint.com", "au", "ea");

3. ?>

1. Welcome to the javaTpoint.com

2. Wulcomu to tha juvuTpoint.com

3. Walcoma to the jeveTpoint.com

4. None of the above

55) What will be the output of the following program?

1. <?php

2. while()

3. {
4. echo "Hello World";

5. }

6. ?>

1. Hello World

2. Infinite loop

3. no output

4. Error

56) What will be the output of the following program?

1. <?php

2. $var1="Hello World";

3. echo strrev("$var1");

4. ?>

1. dlroW olleH

2. olleH dlroW

3. Hello dlroW

4. None of the above

57) Which of the following function is used to compute the difference between two arrays in PHP?

1. diff_array

2. array_diff

3. arrays_diff

4. diff_arrays

58) What will be the output of the following program?

1. <?php

2. $a = array(16, 5, 2);

3. echo array_product($a);

4. ?>

1. 160

2. 1652

3. 80

4. 32

59) Which PHP function converts an English text datetime into a Unix timestamp?

1. str_to_time()

2. strtodate()

3. strtotime()

4. None of the above

60) Which of the following function in PHP returns the time of sunrise of a particular day and location?

1. date_sunrise() 2 date-sunrise() 3 sunrise() 4 None of the above

You might also like