PHP
PHP
5. Which of the following is the correct way to add a comment in PHP code?
a) #
b) //
c) /* */
d) All of the mentioned
<?php
$x = 10;
$y = 20;
else
?>
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
<?php
?>
a) 6
b) 5
c) 4
d) 3
<?php
function multi($num)
if ($num == 3)
if ($num == 7)
if ($num == 8)
if ($num == 19)
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()
<?php
class Example
{
public $name;
function Sample()
?>
a) function sample()
b) echo “This is an example”;
c) public $name;
d) class Example
<?php
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]";
?>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()
<?php
$x = 5;
$y = 10;
function fun()
$y = $GLOBALS['x'] + $GLOBALS['y'];
fun();
echo $y;
?>
a) 5
b) 10
c) 15
d) Error
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 = strip_tags($input,"<i></i>");
echo $input;
?>
i) $_SERVER['PHP_AUTH_USER'].
ii) $_SERVER['PHP_AUTH_USERS'].
iii) $_SERVER['PHP_AUTH_PU'].
iv) $_SERVER['PHP_AUTH_PW'].
<?php
$a = 100;
printf("PHP Quiz");
printf("PHP MCQ");
printf("PHP Program");
?>
a)
PHP Quiz
PHP MCQ
PHP Program
b) PHP Quiz
c) No output
d) PHP MCQ
i) for 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;”;
<?php
$x = 4;
$y = 3
$z = 1;
$z = $z + $x + $y;
echo "$z";
?>
a) 15
b) 8
c) 1
d) $z
<?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
<?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
<?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()
<?php
$i = 5;
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()
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
<?php
echo pos($php);
?>
a) Function
b) File
c) Strings
d) Array
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
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
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()
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()
1. ! (Exclamation)
2. $ (Dollar)
3. & (Ampersand)
4. # (Hash)
1. .php
2. .hphp
3. .xml
4. .html
2. Local
3. Static
4. Global
1. & …… &
2. // ……
3. /* …… */
1. echo
2. write
3. print
1. + (plus)
2. * (Asterisk)
3. . (dot)
4. append()
1. Inbuilt constants
2. User-defined constants
3. Magic constants
4. Default constants
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()
14) Which of the following PHP function is used to generate unique id?
1. id()
2. mdid()
3. uniqueid()
15) Which of the following is the correct way of defining a variable in PHP?
2. $variable_name = value;
3. $variable_name = value
16) Which of the following is the correct use of the strcmp() function in PHP?
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
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()
1. glob()
2. fold()
3. file()
1. createcookie()
2. makecookie()
3. setcookie()
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()
1. delete()
2. unset()
3. unlink()
26) Which of the following function is used to sort an array in descending order?
1. sort()
2. asrot()
3. dsort()
4. rsort()
1. Notepad++
2. Notepad
3. Adobe Dreamweaver
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()
1. Double Quotes
2. Single Quotes
1. $newVar
2. $new_Var
3. $new-var
32) Which of the following is the correct way to create an array in PHP?
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()
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");
1. compress()
2. zip_compress()
3. gzcompress()
4. zip()
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()
41) Which PHP function is capable to read specific number of characters from a file?
1. filegets()
2. fget()
3. fgets()
1. strops()
2. strrpos()
3. strtr()
1. <?php
3. ?>
3. com
4. Error
1. <?php
3. ?>
3. com
4. Error
1. <?php
2. $var1 = "Hello";
3. $var2 = "World";
5. ?>
1. HelloWorld
2. Hello, World
3. Hello World
1. <?php
2. $var1 = "Hello";
3. $var2 = "World";
4. echo "$var1$var2";
5. ?>
1. HelloWorld
2. "$var1$var2"
3. Hello World
1. <?php
2. $a;
3. if ($a)
4. {
5. echo "hi";
6. }
7. else
8. {
10. }
11. ?>
3. Hi
1. <?php
2. $a = 0;
3. while ($a++)
4. {
5. echo "$a";
6. }
7. echo $a;
8. ?>
1. 0
2. 1
3. 01
1. <?php
3. ?>
1. Welcome to the javaTpoint.com
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
1. <?php
2. $x = 15;
3. $y = 20;
5. {
7. }
8. else
9. {
11. }
12. ?>
1. Hii everyone
2. Hello World
1. <?php
3. ?>
1. <?php
2. $a = "1";
3. switch($a)
4. {
5. case 1:
6. echo "Hello";
7. case 2:
8. echo "World";
9. default:
11. }
12. ?>
1. HelloWorld
2. This is javaTpoint.com
3. Hello
4. HelloWorldThis is javaTpoint.com
1. <?php
3. ?>
1. <?php
2. while()
3. {
4. echo "Hello World";
5. }
6. ?>
1. Hello World
2. Infinite loop
3. no output
4. Error
1. <?php
2. $var1="Hello World";
3. echo strrev("$var1");
4. ?>
1. dlroW olleH
2. olleH dlroW
3. Hello dlroW
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
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()
60) Which of the following function in PHP returns the time of sunrise of a particular day and location?