KEMBAR78
PHP Questions Test-1 | PDF | Php | Computer Programming
0% found this document useful (0 votes)
81 views12 pages

PHP Questions Test-1

The document contains a comprehensive set of multiple-choice questions (MCQs) related to PHP programming, covering topics such as PHP definitions, functions, syntax, and features. It includes questions about PHP's history, file handling, variable scopes, and various built-in functions. This material is intended for university exam preparation.

Uploaded by

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

PHP Questions Test-1

The document contains a comprehensive set of multiple-choice questions (MCQs) related to PHP programming, covering topics such as PHP definitions, functions, syntax, and features. It includes questions about PHP's history, file handling, variable scopes, and various built-in functions. This material is intended for university exam preparation.

Uploaded by

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

PHP MCQ for University exam

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 default file extension of PHP files?


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

5. 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

6. 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

7. How to define a function in PHP?


a) functionName(parameters) {function body}
b) function {function body}

Page 1 of 12 by M.P
PHP MCQ for University exam

c) function functionName(parameters) {function body}


d) data type functionName(parameters) {function body}

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

9. 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

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

<?php
$x = 10;
$y = 20;
if ($x > $y && 1||1)
print "WELCOME TO PHP MCQ" ;
else
print "Welcome to COMPUTER LAB";
?>
a) no output
b) Welcome to COMPUTER LAB
c) WELCOME TO PHP MCQ
d) error

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

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

Page 2 of 12 by M.P
PHP MCQ for University exam

12. 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()

13. 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()

14. PHP recognizes constructors by the name _________


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

15. 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

16. 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)
Page 3 of 12 by M.P
PHP MCQ for University exam

PHP Quiz

PHP MCQ

PHP Program

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

17. Which PHP statement will give output as $x on the screen?


a) echo “\$x”;
b) echo “$$x”;
c) echo “/$x”;
d) echo “$x;”;

18. 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

19. 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:

Page 4 of 12 by M.P
PHP MCQ for University exam

print "JavaScript";
}
?>
a) Error
b) 1HTML
c) 1JavaScript
d) 1CSS

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

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

22. Which of the following is not a variable scope in PHP?

1. Extern
2. Local
3. Static
4. Global

23. Which of the following is correct to add a comment in php?

1. & …… &
2. // ……
3. /* …… */
4. Both (b) and (c)

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

1. Inbuilt constants
2. User-defined constants

Page 5 of 12 by M.P
PHP MCQ for University exam

3. Magic constants
4. Default constants

25. Which of the following is used for concatenation in PHP?

1. + (plus)
2. * (Asterisk)
3. append()
4. . (dot)

26. 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

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

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

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


b. The fopen() function is used to open remote server
c. The fopen() function is used to open files in PHP
d. None of the above

29. 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

Page 6 of 12 by M.P
PHP MCQ for University exam

30. 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

31.Which of the following function is used to set cookie in PHP?

1. createcookie()
2. makecookie()
3. setcookie()
4. None of the above

32. 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()

33. 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

34. Which of the following function is used to find files in PHP?

1. glob()
2. fold()
3. file()
4. None of the above

Page 7 of 12 by M.P
PHP MCQ for University exam

35. Which of the following is/are the code editors in PHP?

1. Notepad++
2. Notepad
3. Adobe Dreamweaver
4. All of the above

36. Which of the following function is used to unset a variable in PHP?

1. delete()
2. unset()
3. unlink()
4. None of the above

37. Which of the following function is used to sort an array in descending


order?

1. sort()
2. asrot()
3. dsort()
4. rsort()

38. Which of the following function is used to set cookie in PHP?

1. createcookie()
2. makecookie()
3. setcookie()
4. None of the above

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

40. Which of the following is the correct way to print "Hello World" in PHP?
Advertisement

Page 8 of 12 by M.P
PHP MCQ for University exam

1. "Hello World";
2. write("Hello World");
3. echo "Hello World";
4. None of the above

41. Which PHP function determines the last access time of a file?

1. filetime()
2. fileatime()
3. filectime()
4. None of the above

42. 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

43. 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

44. 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

45. 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.

Page 9 of 12 by M.P
PHP MCQ for University exam

46. 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

47. Which of the following function converts a string to all uppercase?

1. upper()
2. uppercase()
3. struppercase()
4. strtoupper()

48. What does SPL stands for in PHP?

1. Standard PHP Library


2. Simple PHP Library
3. Simple PHP List
4. None of the above

49. Which of the following function is used to compress a string in PHP?

1. compress()
2. zip_compress()
3. gzcompress()
4. zip()

50. Which of the following variable name is invalid?

1. $newVar
2. $new_Var
3. $new-var
4. All of the above

51. 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

Page 10 of 12 by M.P
PHP MCQ for University exam

52. String values in PHP must be enclosed within -

1. Double Quotes
2. Single Quotes
3. Both (a) and (b)
4. None of the above

53. 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

Page 11 of 12 by M.P
PHP MCQ for University exam

Page 12 of 12 by M.P

You might also like