Sie sind auf Seite 1von 284

Module – 3

1. The filesize() function returns the file size in ___________


a) bits
b) bytes
c) kilobytes
d) gigabytes

View Answer
Answer: b
Explanation: The function filesize() returns the size of the specified file and it returns the file size
in bytes on success or FALSE on failure.
2. Which one of the following PHP function is used to determine a file’s last access time?
a) fileltime()
b) filectime()
c) fileatime()
d) filetime()

View Answer
Answer: c
Explanation: The fileatime() function returns a file’s last access time in Unix timestamp format
or FALSE on error.
3. Which one of the following function is capable of reading a file into an array?
a) file()
b) arrfile()
c) arr_file()
d) file_arr()

View Answer
Answer: a
Explanation: The function file() will read the entire file into an array.
4. Which one of the following function is capable of reading a file into a string variable?
a) file_contents()
b) file_get_contents()
c) file_content()
d) file_get_content()

View Answer
Answer: b
Explanation: The function file_get_contents() reads a file into a string. This is the preferred way
to read the contents of a file into a string as it will use memory mapping techniques.

1|P a ge
5. Which one of the following function is capable of reading a specific number of characters
from a file?
a) fgets()
b) fget()
c) fileget()
d) filegets()

View Answer
Answer: a
Explanation: The function fgets() will return a line from an open file. This stops returning on a
new line, at the specified length, or at EOF, whichever comes first. Its prototype is string
fgets(resource handle [, int length]). If the optional length parameter is omitted, 1024 character is
assumed.
6. Which one of the following function operates similarly to fgets(), except that it also strips any
HTML and PHP tags form the input?
a) fgetsh()
b) fgetsp()
c) fgetsa()
d) fgetss()

View Answer
Answer: d
Explanation: The function fgetss() returns a line, with HTML and PHP tags removed, from an
open file. This function operates similarly to fgets(), except that it also strips any HTML and
PHP tags form the input.
7. Which one of the following function outputs the contents of a string variable to the specified
resource?
a) filewrite()
b) fwrite()
c) filewrites()
d) fwrites()

View Answer
Answer: b
Explanation: The function fwrite() writes to an open file. This will stop at the end of the file or
when it reaches the specified length, whichever comes first.

2|P a ge
8. Which function sets the file filename last-modified and last-accessed times?
a) sets()
b) set()
c) touch()
d) touched()

View Answer
Answer: c
Explanation: The function touch() will set the access and modification time of the specified file.
Syntax is touch(filename, time, atime).

9. Which function is useful when you want to output the executed command result?
a) out_cmm()
b) out_system()
c) cmm()
d) system()

View Answer
Answer: d
Explanation: The function system() in PHP is same as the C version of the function as in that it
executes the given command and outputs the result. This function also tries to automatically
flush the web server’s output buffer after each line of output if PHP is running as a server
module.
10. Which one of the following function reads a directory into an Array?
a) scandir()
b) readdir()
c) scandirectory()
d) readdirectory()

View Answer
Answer: a
Explanation: It returns an array consisting of files and directories found in directory or returns
FALSE on error.
11. The file_get_contents function returns the entire contents a file as
a) Integer
b) String
c) Character
d) None of the above

View Answer
Answer: b

3|P a ge
12. Any string can be brocken up into an array by using
a) file()
b) explode()
c) xplode()
d) Both a and b

View Answer
Answer: d

13. For seeing the last time modification of a file, which function is used
a) fileinode()
b) filemtime()
c) file_time()
d) m_time()

View Answer
Answer: b

14. If you would like to read a file character by character which function do you use?
a) fopen()
b) fread()
c) fget()
d) file()

View Answer
Answer: c

15. Which function is used to set a modification time, and create a file if it is not exist
a) unlink()
b) stat()
c) touch()
d) symlink()

View Answer
Answer: c

16. The function fread () has


a) 2 Parameters
b) 3 Parameters
c) 4 Parameters
d) None

View Answer
Answer: a

4|P a ge
17. If you want to make a file public, PHP sets by default its permission to
a) 444 (r--r--r--)
b) 644 (rw-r--r--)
c) 751 (rwxr-x--x)
d) None of them

View Answer
Answer: b

18. Which function returns and caches the size of a file in bytes?
a) feof()
b) filesize ()
c) f_size ( )
d) file_e()

View Answer
Answer: b

19. Unlike fopen (), the result of fclose () does not need to be assigned
a) To a variable
b) To a string
c) To a function
d) To a parameter

View Answer
Answer: a

20. Syslog function allows you to


a) Open a system for a program
b) Generate a message
c) Delete a File
d) Both Aand B

View Answer
Answer: d

5|P a ge
21. Rmdir (directory) function is used for
a) Removing files directory
b) Removing empty directory
c) Removing all old directories
d) All of them

View Answer

Answer: b

22. Which function is identical to fsockopen ()


a) open ()
b) fopen ()
c) pfsockopen ()
d) None of them

View Answer

Answer: c

23. HTTP fopen tries to open an HTTP 1.0 connection to a file of a type
a) 0
b) 1
c) 1.2
d) 1.3

View Answer
Answer: a

24. A socket is a kind of dedicated program that allows different programs to


a) Communicate
b) Send messages between them
c) Create connection with web server
d) All of them

View Answer
Answer: d

6|P a ge
25. Web and database servers communicate via
a) fsockopen ()
b) open ()
c) fopen ()
d) copen ()

View Answer
Answer: a

26. The fpassthru ()function reads all data from the current position in an open file until
a) Middle of the file
b) End of the file
c) First line of the file
d) None of them

View Answer
Answer: b

27. Fileperms ()function returns what?


a) Returns file permission level
b) Returns file parameters
c) Returns file modification time
d) None of them

View Answer
Answer: a

28. Eclose (Sfd) is an example of

a) File write function


b) File close function
c) File read function
d) None of them

View Answer
Answer: b

7|P a ge
29. Shostname, Sport, [error number, error string, timeout in seconds] all are parameters of
a) fsockopen ()
b) pfsockopen ()
c) fopen ()
d) Both A and B

View Answer
Answer: d

30. How many types of calendar are offerd by PHP


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

View Answer
Answer: d

31. Which from the following calendar is offered by PHP


a) Julian
b) Unixian
c) Jewish
d) All of them

View Answer
Answer: d

32. Which function is used to return date information


a) date()
b) time_date()
c) getdate()
d) All of them

View Answer
Answer: c

8|P a ge
33. For checking the existence of DNS record which function is used
a) get_dns()
b) checkdnsrr()
c) get_hostdns()
d) None of them

View Answer
Answer: b

34. A large number of PHP function are duplicated from


a) Windows
b) Macintosh
c) Unix
d) All of them

View Answer
Answer: c

35.Which one from the following is a DNS function?


a) stat()
b) symlink()
c) getthostbyaddr()
d) All if them

View Answer
Answer: c

36. Which Symbol is used for read and write even if the file doesn’t exists already?
a) a+
b) r+
c) w+
d) w-

View Answer
Answer: c

9|P a ge
37. A filesystem function clearstatcatche() id used for
a) Deleting files
b) Changing the state of catch
c) Clears catch of file status info
d) None of them

View Answer
Answer: c

38. The fread() function will stop at the end of the file or when it reaches to
a) The specified location
b) The specied width
c) The specied length
d) All of them

View Answer
Answer: c

39. Mktime ( ) function allows you to convert any date into a


A. String

B. Characters

C. Timestamp

D. None of them

View Answer
Answer: c

40. File_get_contents function is included in


A. PHP1

B. PHP2.1

C. PHP3.4.0

D. PHP4.3.0

View Answer
Answer: d

10 | P a g e
41. What will be the output of the following PHP code?

1. <?php
2. echo (checkdate(4,31,2010) ? 'Valid' : 'Invalid');
3. ?>
a) TRUE
b) FALSE
c) Valid
d) Invalid
View Answer
Answer: d
Explanation: The function checkdate() is used to validate a Gregorian date. In the program, April
has 30 days and the above date is 31 therefore Invalid is returned.
42. The date() function returns ___ representation of the current date and/or time.
a) Integer
b) String
c) Boolean
d) Float
View Answer
Answer: b
Explanation: The function date() is used to format a local date and time, and it will return the
formatted date string. The syntax of this function is string date(string format [, int timestamp]).

43. Which one of the following format parameter can be used to identify timezone?
a) T
b) N
c) E
d) I
View Answer
Answer: c
Explanation: When the format is E the time zone is identified and returned, for example,
America/New York. N denotes ISO-8601 numeric representation of the day of the week, T
denotes time zone abbreviation, I denotes whether or not the date is in daylight saving time.
44. If the format is F then which one of the following will be returned?
a) Complete text representation of month
b) Day of month, with leading zero
c) Daylight saving time
d) Day of month, without zeros
View Answer
Answer: a
Explanation: F represents a full textual representation of a month, such as January or March. Day
of month, with leading zero is represented by D, Daylight saving time by I, Day of month
without zeros by j.

11 | P a g e
45. What will be the output of the following code? (If say date is 22/06/2013.)

1. <?php
2. echo "Today is ".date("F d, Y");
3. ?>
a) Today is 22 June, 2013
b) Today is 22-06-2013
c) Today is 06-22-2013
d) Today is June 22, 2013
View Answer
Answer: d
Explanation: The function date() is used to format a local date and time, and it will return the
formatted date string. F is the parameter for complete text representation of month, d for day of
month, and Y for 4 digit representation of year.
46. Which one of the following function is useful for producing a timestamp based on a given
date and time?
a) time()
b) mktime()
c) mrtime()
d) mtime()
View Answer
Answer: b
Explanation: The function mktime() returns the Unix timestamp for a date. This function is same
as gmmktime() except that the passed parameters represents a date not a GMT date.

47. Which function displays the web page’s most recent modification date?
a) lastmod()
b) getlastmod()
c) last_mod()
d) get_last_mod()
View Answer
Answer: b
Explanation: The function getlastmod() gets the time of the last modification of the main script
of execution. It returns the value of the page’s last modified header or FALSE in the case of an
error.

12 | P a g e
48. What will be the output of the following PHP code? (If say date is 22/06/2013.)

1. <?php
2. printf( date("t") );
3. ?>
a) 30
b) 22
c) JUNE
d) 2013
View Answer
Answer: a
Explanation: The t parameter is used to determine the number of days in the current month.
49. Suppose you want to calculate the date 45 days from the present date which one of the
following statement will you use?
a) totime(“+45”)
b) totime(“+45 days”)
c) strtotime(“+45 days”)
d) strtotime(“-45 days”)
View Answer
Answer: c
Explanation: The strtotime() function and GNU date syntax is used to calculating the date x days
from the present date.

50. To create an object and set the date to JUNE 22, 2013, which one of the following statement
should be executed?
a) $date = Date(“22 JUNE 2013”)
b) $date = new Date(“JUNE 22 2013”)
c) $date = DateTime(“22 JUNE 2013”)
d) $date = new DateTime(“22 JUNE 2013”)
View Answer
Answer: d
Explanation: The dateTime() method is class constructor. You can set the date either at the time
of instantiation or later by using a variety of mutators.
51. How many methods does the DateTime class have?
a) 8
b) 9
c) 10
d) 11
View Answer
Answer: b
Explanation: The DateTime class has nine methods, all of which are public.

13 | P a g e
52. How many constants does the DateTime class have?
a) 8
b) 9
c) 10
d) 11
View Answer
Answer: d
Explanation: The DateTime class has 11 constants, no static properties or methods.

53. Which method is simply an object-oriented version of date()?


a) DateTime::format()
b) DateTime::modify()
c) DateTime::setTime()
d) DateTime::setDate()
View Answer
Answer: a
Explanation: The format() method is simply an object-oriented version of date(). It takes
$dateFormat as an argument. $dateFormat is a string consisting of the same date formatting
characters accepted by the procedural date() function.
54. Which of the following is the right way to use the DateTime class?
a) $date = get_Class(DateTime);
b) $date = class DateTime;
c) $date = new DateTime();
d) $date = new class DateTime();
View Answer
Answer: c
Explanation: The way you use the DateTime class is like any other class: instantiate an object,
and store it in a variable.
55. What will be the output of the following PHP code if date is 24/02/2008?

1. <?php
2. $date = new DateTime();
3. echo $date->format('l,F,js,Y');
4. ?>
a) Sunday, February 24th 2008
b) Sunday, 02 24 2008
c) Sunday, 24 02 2008
d) Sunday, 24th February 2008
View Answer
Answer: a
Explanation: The format() method displays the date in same way as standard date function().

14 | P a g e
56. Which of the following statements can be used to set the time zone in individual scripts?
a) date_set_timezone(‘Europe/London’);
b) date_default_timezone_set(‘Europe/London’);
c) date_set_default_timezone(‘Europe/London’);
d) date_default_timezone(‘Europe/London’);
View Answer
Answer: b
Explanation: The function date_default_timezone_set is used to set the default time zone used by
all date/time functions in a script. You can also use ini_set(‘date.timezone’, ‘Europe/London’);
57. Which of the following DateTimeZone classes are static?

i) listAbbreviations()

ii) getName()

iii) getOffset()

iv) listIdentifiers()

a) Only i)
b) Only ii)
c) i) and iv)
d) iii) and iv)
View Answer
Answer: c
Explanation: listAbbreviations() and listIdentifiers() are static methods.

15 | P a g e
58. Which of the following DateTimeZone classes are non-static?

i) _construct()

ii) getName()

iii) getOffset()

iv) getTransitions()

a) Only i)
b) Only ii)
c) i), ii), iii) and iv)
d) iii) and iv)
View Answer
Answer: c
Explanation: All of the given methods are non static.

59. Which of the following statements can be used to add two months to the existing date?
a) $date->modify(‘+2 months’);
b) $date = modify(‘+2 months’);
c) $date = modify(‘2+ months’);
d) $date->modify(‘2+ months’);
View Answer
Answer: a
Explanation: To change the date stored by a DateTime object after it has been created, you use
DateTime::modify() with a natural language expression.
60. Which method enables you to calculate whether daylight saving time is in force at a specific
date and time?
a) getOffset()
b) getTranitions()
c) ISODate()
d) savingTime()
View Answer
Answer: b
Explanation: This outputs a multidimensional array listing past and future changes to the offset
from UTC for a DateTimeZone object.

16 | P a g e
61. Which two predefined variables are used to retrieve information from forms?
a) $GET & $SET
b) $_GET & $_SET
c) $__GET & $__SET
d) GET & SET
View Answer
Answer: b
Explanation: The global variables $_GET is used to collect form data after submitting an HTML
form with the method=”get”. The variable $_SET is also used to retrieve information from
forms.

62. The attack which involves the insertion of malicious code into a page frequented by other
users is known as _______________
a) basic sql injection
b) advanced sql injection
c) cross-site scripting
d) scripting
View Answer
Answer: c
Explanation: The cross-site scripting attack is among one of the top five security attacks carried
out across the Internet. It is also known as XSS, this attack is a type of code injection attack
which is made possible by incorrectly validating user data, which usually gets inserted into the
page through a web form or using an altered hyperlink.
63. When you use the $_GET variable to collect data, the data is visible to ___________
a) none
b) only you
c) everyone
d) selected few
View Answer
Answer: c
Explanation: The information sent from a form with the method GET is visible to everyone i.e.
all variable names and values are displayed in the URL.
64. When you use the $_POST variable to collect data, the data is visible to ___________
a) none
b) only you
c) everyone
d) selected few
View Answer
Answer: b
Explanation: The information sent from a form with the method POST is invisible to others i.e.
all names/values are embedded within the body of the HTTP request.

17 | P a g e
65. Which variable is used to collect form data sent with both the GET and POST methods?
a) $BOTH
b) $_BOTH
c) $REQUEST
d) $_REQUEST
View Answer
Answer: d
Explanation: In PHP the global variable $_REQUEST is used to collect data after submitting an
HTML form.
66. Which one of the following should not be used while sending passwords or other sensitive
information?
a) GET
b) POST
c) REQUEST
d) NEXT
View Answer
Answer: a
Explanation: The information sent from a form with the method GET is visible to everyone i.e.
all variable names and values are displayed in the URL. So, it should not be used while sending
passwords or other sensitive information.
67. Which function is used to remove all HTML tags from a string passed to a form?
a) remove_tags()
b) strip_tags()
c) tags_strip()
d) tags_remove()
View Answer
Answer: b
Explanation: The function strip_tags() is used to strip a string from HTML, XML, and PHP tags.
68. What will be the value of the variable $input in the following PHP code?

1. <?php
2. $input = "Swapna<td>Lawrence</td>you are really<i>pretty</i>!";
3. $input = strip_tags($input,"<i></i>");
4. echo $input;
5. ?>
a) Swapna Lawrence you are really pretty!
b) Swapna <td>Lawrence</td> you are really<i>pretty</i>!
c) Swapna <td>Lawrence</td> you are really pretty!
d) Swapna Lawrence you are really<i>pretty</i>!
View Answer
Answer: d
Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially
wreak havoc on a page.

18 | P a g e
69. To validate an email address, which flag is to be passed to the function filter_var()?
a) FILTER_VALIDATE_EMAIL
b) FILTER_VALIDATE_MAIL
c) VALIDATE_EMAIL
d) VALIDATE_MAIL
View Answer
Answer: a
Explanation: The FILTER_VALIDATE_EMAIL is used to validates an e-mail address.

70. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?
a) 5
b) 6
c) 7
d) 8
View Answer
Answer: c
Explanation: There are seven validation filters. They are FILTER_VALIDATE_EMAIL,
FILTER_VALIDATE_BOOLEAN, FILTER_VALIDATE_FLOAT,
FILTER_VALIDATE_INT, FILTER_VALIDATE_IP, FILTER_VALIDATE_REGEXP,
FILTER_VALIDATE_URL.
71. How many predefined variables does PHP use to authenticate a user?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: b
Explanation: The variables PHP use to authenticate a user are
$_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’].
72. 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) i) and ii)
b) ii) and iv)
c) i) and iv)
d) ii) and iii)
View Answer
Answer: c
Explanation: $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’] store the
username and password values, respectively.

19 | P a g e
73. Which of the following PHP function is commonly used when handling authentication via
PHP?

i) header()

ii) footer()

iii) inset()

iv) isset()

a) i) and iv)
b) ii) and iv)
c) ii) and iii)
d) i) and iii)
View Answer
Answer: a
Explanation: The function isset () is used to check whether a variable is set or not and the
function header() sends a raw HTTP header to a client.

74. Which function is used to verify whether a variable contains a value?


a) header()
b) footer()
c) inset()
d) isset()
View Answer
Answer: d
Explanation: The isset() function determines whether a variable has been assigned a value. Its
prototype follows: boolean isset(mixed var [,mixed var [,…]]).

20 | P a g e
75. Which of the following are types of PHP authentication implementation methodologies?

i) Hard-coding a login pair directly into the script

ii) File-based authentication

iii) Data-based authentication

iv) PEAR'S HTTP authentication

a) ii) and iii)


b) i) and iv)
c) i), ii), iii) and iv)
d) Only iv)
View Answer
Answer: c
Explanation: The method PEAR’S HTTP authentication is used to provides a framework for user
authentication on the HTTP. The data-based authentication is the process of confirming that a
user who is attempting to log in to a database is authorized to do so. In the file-based
authentication as some small sites does not have a need for database back-end to store data, but
security is still important either the site is big or small. They need to authenticate some folder or
file and want to set access credentials for that. One can handle such by using file-based
authentication using PHP. The simplest way to restrict resource access is by hard-coding the
username and password directly into the script.
76. In which authentication method does changing the username or password can be done only
by entering the code and making the manual adjustment.
a) Hard-coding a login pair directly into the script
b) File-based authentication
c) Data-based authentication
d) PEAR’S HTTP authentication
View Answer
Answer: a
Explanation: The simplest way to restrict resource access is by hard-coding the username and
password directly into the script. In this authentication method, changing the username or
password can be done only by entering the code and making the manual adjustment. This is one
of the drawbacks of hard-coding a login pair directly into the script.

21 | P a g e
77. The authenticationFile.txt, the file which stores username and password should be stored ___
the server document root.
a) Inside
b) Outside
c) Within
d) None of the mentioned
View Answer
Answer: b
Explanation: If it is not stored outside, the attacker could discover the file through brute force
guessing.

78. Which function is used to split a string into a series of substrings, with each string boundary
is determined by a specific separator?
a) break()
b) divide()
c) explode()
d) md5()
View Answer
Answer: c
Explanation: Although they are a similar function, you should use explode() instead of split(). In
fact split() function has been deprecated altogether.
79. In which of the following situations does file-based authentication become inconvenient.

i) small list

ii) large number of user

iii) users are being regularly added

iv) static authentication

a) i) and iv)
b) i) and iii)
c) ii) and iii)
d) ii) and iv)
View Answer
Answer: c
Explanation: Such requirements are better satisfied by implementing a database based solution.

22 | P a g e
80. Which is the most powerful authentication method among the four?
a) Hard-coding a login pair directly into the script
b) File-based authentication
c) Data-based authentication
d) PEAR’S HTTP authentication
View Answer
Answer: c
Explanation: It not only enhances administrative convenience and scalability but also can be
integrated into a larger database infrastructure.
81. Which directive determines whether PHP scripts on the server can accept file uploads?
a) file_uploads
b) file_upload
c) file_input
d) file_intake
View Answer
Answer: a
Explanation: With PHP, it is easy to upload files to the server. We need to ensure that PHP is
configured to allow file uploads. In the “php.ini” file, search for the file_uploads directive, and
set it to On. By default, its value is on.
82. Which of the following directive determines the maximum amount of time that a PHP script
will spend attempting to parse input before registering a fatal error?
a) max_take_time
b) max_intake_time
c) max_input_time
d) max_parse_time
View Answer
Answer: c
Explanation: This is relevant because particularly large files can take some time to upload,
eclipsing the time set by this directive.
83. What is the default value of max_input_time directive?
a) 30 seconds
b) 60 seconds
c) 120 seconds
d) 1 second
View Answer
Answer: b
Explanation: The default value of the max_input_time directive is 60 seconds.

23 | P a g e
84. Since which version of PHP was the directive max_file_limit available.
a) PHP 5.2.1
b) PHP 5.2.2
c) PHP 5.2.12
d) PHP 5.2.21
View Answer
Answer: c
Explanation: The max_file_limit directive sets an upper limit on the number of files which can
be simultaneously uploaded.
85. What is the default value of the directive max_file_limit?
a) 10 files
b) 15 files
c) 20 files
d) 25 files
View Answer
Answer: c
Explanation: The default value of the directive max_file_limit is 20 files.
86. Which directive sets a maximum allowable amount of memory in megabytes that a script can
allow?
a) max_size
b) post_max_size
c) max_memory_limit
d) memory_limit
View Answer
Answer: d
Explanation: Its default value is 16M.
87. If you want to temporarily store uploaded files in the /tmp/phpuploads/ directory, which one
of the following statement will you use?
a) upload_tmp_dir “/tmp/phpuploads/ directory”
b) upload_dir “/tmp/phpuploads/ directory”
c) upload_temp_dir “/tmp/phpuploads/ directory”
d) upload_temp_director “/tmp/phpuploads/ directory”
View Answer
Answer: a
Explanation: Anyone can temporarily store uploaded files on the given directory. One cannot
change upload_tmp_dir at the runtime. By the time a script runs, the upload process has already
occurred.

24 | P a g e
88. Which superglobal stores a variety of information pertinent to a file uploaded to the server
via a PHP script?
a) $_FILE Array
b) $_FILES Array
c) $_FILES_UPLOADED Array
d) $_FILE_UPLOADED Array
View Answer
Answer: b
Explanation: The superglobal $_FILES is a two-dimensional associative global array of items
which are being uploaded by via HTTP POST method and holds the attributes of files.

89. How many items are available in the $_FILES array?


a) 2
b) 3
c) 4
d) 5
View Answer
Answer: d
Explanation: $_FILEs[‘userfile’][‘error’], $_FILEs[‘userfile’][‘name’],
$_FILEs[‘userfile’][‘size’], $_FILEs[‘userfile’][‘tmp_name’], $_FILEs[‘userfile’][‘type’] are the
five items in the array.
90. Which function is used to determine whether a file was uploaded?
a) is_file_uploaded()
b) is_uploaded_file()
c) file_uploaded(“filename”)
d) uploaded_file(“filename”)
View Answer
Answer: b
Explanation: The function is_uploaded_file() checks whether the specified file is uploaded via
HTTP POST. The syntax is is_uploaded_file(file).
91. What is the full form of DNS?
a) Digital Network System
b) Domain Network System
c) Digital Name Systmem
d) Domain Name System
View Answer
Answer: d
Explanation: DNS stands for domain name system. It is the way that internet domain names are
located and translated into internet protocol (IP) addresses. For example, if someone types
abc.com into the web browser, a server behind the scenes will map that name to the IP address
206.16.49.139.

25 | P a g e
92. Which one of the following function checks for the existence of DNS records?
a) checkdns()
b) checkdnsr()
c) checkdnsrr()
d) checkdnsa()
View Answer
Answer: c
Explanation: The function checkdnsrr() is used to check DNS records for type corresponding to
host. DNS records are checked based on the supplied host value and optional DNS resource
record type, returning TRUE if any records are located and FALSE otherwise.

93. Which one of the following function is used to return an array consisting of various DNS
resource records pertinent to a specific domain?
a) dns_get_record()
b) dns_record()
c) dnsrr_get_record()
d) dnsrr_record()
View Answer
Answer: a
Explanation: The function dns_get_record() is used to get the DNS resource records associated
with the specified hostname. This function is used to return an array consisting of various DNS
resource records pertinent to a specific domain.
94. Which one of the following function is used to retrieve the MX records for the domain
specified by hostname?
a) getmx()
b) retrieve_mx()
c) getmxrr()
d) retrieve_mxrr()
View Answer
Answer: c
Explanation: The function getmxrr() returns the MX records for the specified internet host name.
This function is used to retrieve the MX records for the domain specified by hostname.
95. What is the default port number of HTTPs?
a) 70
b) 80
c) 90
d) 100
View Answer
Answer: b
Explanation: By default, The port number HTTP uses is port 80 and HTTPS uses port 443, but a
URL like http://www.abc.com:8080/path/ specifies that the web browser connects instead to port
8080 of the HTTP servers.

26 | P a g e
96. Which one of the following function returns the port number of a specified service?
a) getportname()
b) getservername()
c) getserverbyname()
d) getservbyname()
View Answer
Answer: d
Explanation: The function fgetservbyname() returns the port number for a given Internet service
and protocol. Example-getservbyname(“http”,”tcp”) will return 80.
97. Which one of the following statements can be used to establish port 80 connection with
www.nachi.com?
a) fsockopen(“www.nachi.com”, 80);
b) sockopen(80,”www.nachi.com”);
c) fsockopen(80,”www.nachi.com”);
d) sockopen(“www.nachi.com”, 80);
View Answer
Answer: a
Explanation: The fsockopen() function establishes a connection to the resource designated by
target on port.
98. Which one of the following function is used to send an email using PHP script?
a) mail_send()
b) send_mail()
c) mailrr()
d) mail()
View Answer
Answer: d
Explanation: The function mail() allows you to send emails directly from a script. Using
mail(string to, string subject, string message), you can send any mail.
99. How many configuration directives pertinent to PHP’s mail function are available?
a) 4
b) 5
c) 6
d) 7
View Answer
Answer: b
Explanation: They are- SMTP, sendmail_from, sendmail_path, smtp_port,
mail.force_extra_parameters.

27 | P a g e
100. Which of the following statements is used to add an attachment to the mail?
a) $mimemail->attachment(‘attachment.pdf’);
b) $mimemail=>attachment(‘attachment.pdf’);
c) $mimemail->addAttachment(‘attachment.pdf’);
d) $mimemail=>addAttachment(‘attachment.pdf’);
View Answer
Answer: c
Explanation: Call the Mail_Mime object’s addAttachment() method passing in the attachment
name and extension.
101. Which one of the following statements should be used to disable just the fopen(), and file()
functions?
a) disable_functions = fopen(), file()
b) disable_functions = fopen, file
c) functions_disable = fopen(), file()
d) functions_disable = fopen, file
View Answer
Answer: b
Explanation: You can set disable_functions equal to a comma-delimited list of function names
that you want to disable.
102. Which one of the following statements should be used to disable the use of two classes
administrator and janitor?
a) disable_classes = “administrator, janitor”
b) disable_classes = class administrator, class janitor
c) disable_classes = class “administrator”, class “janitor”
d) disable_class = class “administrator”, class “janitor”
View Answer
Answer: a
Explanation: There may be classes inside the libraries that you’d rather not make available. You
can prevent the use of these classes with the disable_classes directive.
103. What is the default value of max_execution_time directive? This directive specifies how
many seconds a script can execute before being terminated.
a) 10
b) 20
c) 30
d) 40
View Answer
Answer: c
Explanation: This can be useful to prevent users’ scripts from consuming too much CPU time. If
max_execution_time is set to 0, no time limit will be set.

28 | P a g e
104. The memory_limit is only applicable if ________ is enabled when you configure PHP.
a) –enable-limit
b) -enable-memory-limit
c) –enable-memory-limit
d) -memory-limit
View Answer
Answer: c
Explanation: This directive specifies, in megabytes, how much memory a script can use. Default
value: 128M.
105. Suppose all web material is located within the directory /home/www. To prevent users from
viewing and manipulating files such as /etc/password, which one of the following statements
should you use?
a) open_dir = “/home/www/”
b) open_dir = /home/www/
c) open_basedir = /home/www/
d) open_basedir = “/home/www/”
View Answer
Answer: d
Explanation: We can use open_basedir statement to define the paths from which we can access
files using functions like fopen() and gzopen(). It is used to prevent users from viewing and
manipulating files such as /etc/password.
106. Which Apache directive outputs Apache’s server version, server name, port and compile-in
modules?
a) ServerSignature
b) ServerName
c) ServerDetails
d) ServerInfo
View Answer
Answer: a
Explanation: It is capable of displaying output like: Apache/2.2.11 (Ubuntu) Server at localhost
Port 80.
107. Which directive determines which degree of server details is provided if the
ServerSignature directive is enabled?
a) ServerAddons
b) ServerExtra
c) ServerTokens
d) ServerDetails
View Answer
Answer: c
Explanation: Six options are available: Full, Major, Minimal, Minior, OS, and Prod. If it is set to
Full ‘Apache/2.2.11 (Ubuntu) PHP/5.3.2 Server’ will be displayed.

29 | P a g e
108. Which directive should we disable to obscure the fact that PHP is being used on our server?
a) show_php
b) expose_php
c) print_php
d) info_php
View Answer
Answer: b
Explanation: Using the expose_php directive we can prevent PHP version details from being
appended on our web server signature. When expose_php is disabled, the server signature will
look like: Apache/2.2.11 (Ubuntu) Server.

109. Say I want to change the extension of a PHP file, which of the following statements should I
edit to change from .php to .html in the httpd.conf file?
a) AddType application/x-httpd-php .php
b) AddType application/x-httpd-php .asp
c) AddType application/x-httpd-asp .php
d) AddType application/x-httpd-asp .asp
View Answer
Answer: a
Explanation: Just change the .php to .html and your extension will change. This is used for
security purpose.
110. The developers of PHP deprecated the safe mode feature as of which PHP version.
a) PHP 5.1.0
b) PHP 5.2.0
c) PHP 5.3.0
d) PHP 5.3.1
View Answer
Answer: c
Explanation: This happened because safe mode often creates many problems as it resolves,
largely due to the need for enterprise applications to use many of the features safe mode disables.
111. What will be the output of the following PHP code?

1. <?php
2. $number = array(0,1,two,three,four,5);
3. $num = preg_grep("/[0-5]/", $number);
4. print_r($num);
5. ?>
a) Array([0]=>0 [1]=>1 [2]=>two [3]=>three [4]=>four [5]=>5)
b) Array([2]=>two [3]=>three [4]=>four)
c) Array([1]=> 1)
d) Array([0]=>0 [1]=>1 [5]=>5)
View Answer
Answer: d
Explanation: The preg_grep function is used to search an array for specific patterns and then
return a new array based on that filtering.
30 | P a g e
112. What will be the output if we replace the line $num = preg_grep(“/[0-5]/”, $number); with
$num = preg_grep(“/[0-5]/”, $number, PREG_GREP_INVERT);?
a) Array([0]=>0 [1]=>1 [2]=>two [3]=>three [4]=>four [5]=>5)
b) Array([2]=>two [3]=>three [4]=>four)
c) Array([1]=> 1)
d) Array([0]=>0 [5]=>5)
View Answer
Answer: b
Explanation: When we include PREG_GREP_INVERT, this will invert our data, so instead of
outputting numbers it will output our non-numeric values.

113. Which one of the following functions are used to search a string?
a) preg_match
b) preg_search
c) preg_find
d) preg_found
View Answer
Answer: a
Explanation: The function preg_match() searches string for pattern and it returns true if pattern
exists, and false otherwise. The function returns 1 if search was successful else returns 0.
114. What will be the output of the following PHP code?

1. <?php
2. $name = "What is your name?";
3. if (preg_match("/name/"),$name)
4. echo "My name is Will Pitt ";
5. else
6. echo "My name is not Will Pitt ";
7. if (preg_match("/are/"))
8. echo "I am great";
9. else
10. echo "I am not great";
11. ?>
a) My name is Will Pitt I am great
b) My name is not Will Pitt I am great
c) My name is Will Pitt I am not great
d) My name is not Will Pitt I am not great
View Answer
Answer: c
Explanation: The code uses preg_match to check for a keyword and replies based on whether it
is true (1) or false (0).

31 | P a g e
115. Which one of the following preg PHP function is used to do a find and replace on a string or
an array?
a) preg_replace()
b) preg_find()
c) preg_find_replace()
d) preg_findre()
View Answer
Answer: a
Explanation: In preg_replace() function, after the replacement has occurred, the modified string
will be returned and if no matches are found, the string will remain unchanged.

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

1. <?php
2. $str = "Hello! My name is Cameron Fox. Coffee?";
3. $find = array('/is/','/coffee/');
4. $replace = array('/was/','/tea/');
5. echo preg_replace ($find, $replace, $str);
6. ?>
a) Hello! My name was Cameron Fox. tea?
b) Hello! My name is Cameron Fox. tea?
c) Hello! My name is Cameron Fox. Coffee?
d) Hello! My name was Cameron Fox. Coffee?
View Answer
Answer: d
Explanation: Coffee was not replaced because the preg_replace function is case sensitive.
Therefore it treats coffee and Coffee differently.

117. Which one of the following preg PHP functions is used to take a string, and put it in an
array?
a) preg_destroy()
b) preg_split()
c) preg_unchain()
d) preg_divide()
View Answer
Answer: b
Explanation: The string is broken up into different values in the array based upon your input.

32 | P a g e
118. What will be the output of the following PHP code?

1. <?php
2. $line = "You like dogs. I hate dogs. We should marry.";
3. $sen = preg_split('/\./', $line);
4. print_r($sen);
5. ?>
a) You like dogs. I hate dogs. We should marry.
b) Array([0]=>You like dogs. I hate dogs. We should marry.)
c) Array([0]=>You like dogs. [1]=>I hate dogs. [2]=>We should marry.)
d) Error
View Answer
Answer: c
Explanation: We use a ‘.’ period to split the data, therefor giving each sentence it’s own array
entry.
119. Which one of the following is not a preg PHP function?
a) preg_match
b) preg_match_all
c) preg_matchall
d) preg_split
View Answer
Answer: c
Explanation: The function preg_match_all() matches all occurrences of pattern in string.
120. Parameter flags was added in which version of PHP?
a) PHP 4.0
b) PHP 4.1
c) PHP 4.2
d) PHP 4.3
View Answer
Answer: d
Explanation: Parameter flags was added in PHP 4.3 version.

121. How many error levels are available in PHP?


a) 14
b) 15
c) 16
d) 17
View Answer
Answer: c
Explanation: Whenever the PHP engine encounters any problem that prevents a script from
running properly it generates an error message. There are sixteen error levels and each level is
represented by an integer value and an associated constant.

33 | P a g e
122. What is the description of Error level E_ERROR?
a) Fatal run-time error
b) Near-fatal error
c) Compile-time error
d) Fatal Compile-time error
View Answer
Answer: a
Explanation: E_ERROR is a fatal run-time error, that can’t be recovered from and the execution
of the script is stopped immediately.
123. Which version of PHP introduced E_STRICT Error level?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3
View Answer
Answer: b
Explanation: E_STRICT is PHP version portability suggestions. It is not strictly an error, but it is
triggered whenever PHP encounters code that could lead to problems or forward
incompatibilities.
124. Which character does the error_reporting directive use to represent the logical operator
NOT?
a) /
b) !
c) ~
d) ^
View Answer
Answer: c
Explanation: The twidle (~) character is used to represent the logical operator NOT.
125. Say you want to report error concerned about fatal run-time, fatal compile-time error and
core error which statement would you use?
a) error_reporting = E_ALL
b) error_reporting = E_ERROR | E_PARSE | E_CORE_ERROR
c) error_reporting = E_ERROR | E_COMPILE_WARNING | E_CORE_ERROR
d) error_reporting = E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR
View Answer
Answer: d
Explanation: E_ERROR is a fatal run-time error, that can’t be recovered from.
E_COMPILE_ERROR is a fatal error that occurs while the script was being compiled. And
E_CORE_ERROR is a fatal error that occurs during the PHP’s engine initial startup.

34 | P a g e
126. Which version introduced the function error_get_last()?
a) PHP 4
b) PHP 5
c) PHP 5.2
d) PHP 5.3
View Answer
Answer: c
Explanation: This function returns an associative array consisting of the type, message, file, and
line of the last occurring error.
127. Which of the following statements causes PHP to disregard repeated error messages that
occur within the same file and on the same line?
a) ignore_repeated_errors
b) ignore_repeat_error
c) repeatedly_ignore_error
d) repeated_error_ignore
View Answer
Answer: a
Explanation: ignore_repeated_errors will not log repeated messages. The repeated errors must
occur in the same file on the same line unless ignore_repeated_source is set to true.
128. Which function initializes the constants necessary for using the openlog(), clodelog(), and
syslog() functions?
a) define_variable()
b) define_log_variable()
c) log_variable()
d) define_syslog_variable()
View Answer
Answer: d
Explanation: If you’re running PHP version 5.2.X or older, you need to execute this function
before using any of the following logging functions.
129. Which logging option’s description is if an error occurs when writing to the syslog, send
output to the system console?
a) LOG_CONS
b) LOG_NDELAY
c) LOG_ODELAY
d) LOG_PERROR
View Answer
Answer: a
Explanation: If there is an error while sending data to the system logger, LOG_CONS will write
directly to the system console.

35 | P a g e
130. Which function is responsible for sending a custom message to the system log?
a) systemlog()
b) syslog()
c) log_system()
d) sys_log()
View Answer
Answer: b
Explanation: The function syslog() generates a log message that will be distributed by the system
logger.
131. Which version of PHP was added with Exception handling?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6
View Answer
Answer: b
Explanation: Exception handling was added to PHP with the version 5 release, and further
enhanced with version 5.3.
132. How many methods are available for the exception class?
a) 5
b) 6
c) 7
d) 8
View Answer
Answer: c
Explanation: The seven methods are: getCode(), getFile(), getLine(), getMessage(),
getPrevious(), getTrace(), getTraceAsString().
133. Which version added the method getPrevious()?
a) PHP 4
b) PHP 5
c) PHP 5.1
d) PHP 5.3
View Answer
Answer: d
Explanation: The function getPrevious() returns previous exception.
134. Which of the following statements invoke the exception class?
a) throws new Exception();
b) throw new Exception();
c) new Exception();
d) new throws Exception();
View Answer
Answer: b
Explanation: throw new Exception(); trigger an exception and each “throw” must have at least
one “catch”.

36 | P a g e
135. Which one of the following is the right description for the method getMessage()?
a) Returns the message if it is passed to the constructor
b) Returns the message if it is passed to the class
c) Returns the message if it is passed to the file
d) Returns the message if it is passed to the object
View Answer
Answer: a
Explanation: The function getMessage() gets the exception message. It returns the message if it
is passed to the constructor.
136. You can extend the exception base class, but you cannot override any of the preceding
methods because the are declared as__________
a) protected
b) final
c) static
d) private
View Answer
Answer: b
Explanation: Marking a method as final prevents it from being overridden by a subclass.
137. What does SPL stand for?
a) Standard PHP Library
b) Source PHP Library
c) Standard PHP List
d) Source PHP List
View Answer
Answer: a
Explanation: The standard PHP library(SPL) extends PHP by offering ready-made solutions to
commonplace tasks such as file access, iteration of various sorts etc.
138. How many predefined exceptions does SPL provide access to?
a) 13
b) 14
c) 15
d) 16
View Answer
Answer: a
Explanation: It provides 13 exceptions: BadFunctionCallException, BadMethodCallException,
DomainException, InvalidArgumentException, LengthException, LogicException,
OutOfBoundsException, OutOfRangeException, OverflowException, RangeException,
RuntimeException, UnderflowException, UnexpectedValueException.

37 | P a g e
139. Which of the following is/are an exception?

i) BadFunctionCallException

ii) BadMethodCallException

iii) LogicException

iv) DomainException

a) Only ii)
b) Only iii)
c) i), ii), iii) and iv)
d) Only iv)
View Answer
Answer: c
Explanation: There are total 13 types of predefined exceptions SPL provide access to.
BadFunctionCallException,BadMethodCallExceptio, LogicException, DomainException are
also included in the exceptions.

140. Which of the following is/are an exception?

i) OutOfBoundException

ii) OutOfRangeException

iii) OverflowException

iv) UnderflowException

a) i)
b) i) and iii)
c) i) and ii)
d) i), ii), iii) and iv)
View Answer
Answer: d
Explanation: The exception is thrown if a value is not a valid key. This represents errors that
cannot be detected at compile time. OutOfBoundException, OutOfRangeException,
OverflowException, UnderflowException are valid exceptions in PHP.

38 | P a g e
141. Which of the following is/are an external data?

i) Cookies

ii) Input data from a form

iii) Server Variables

iv) Web services data

a) Only ii)
b) ii) and iii)
c) Only iii)
d) i), ii), iii) and iv)
View Answer
Answer: d
Explanation: The web applications receives external input. External input/data can be: User input
from a form, Cookies, Web services data, Server variables and, Database query results.
142. How many types of filtering are present in PHP?
a) 3
b) 2
c) 4
d) None
View Answer
Answer: b
Explanation: There are two main types of filtering: validation and sanitization.
143. Which one of the following filter is used to filter several variables with the same or different
filters?
a) filter_var_array()
b) filter_var()
c) filter_input
d) filter_input_array
View Answer
Answer: a
Explanation: The function filter_var_array() can get multiple variables and it optionally filters
them. The function is useful for filtering many values without calling filter_var().

39 | P a g e
144. What will be the output of the following PHP code?

1. <?php
2. $num = "123";
3. if (!filter_var($num, FILTER_VALIDATE_INT))
4. echo("Integer is not valid");
5. else
6. echo("Integer is valid");
7. ?>
a) No output is returned
b) Integer is not valid
c) Integer is valid
d) Error
View Answer
Answer: c
Explanation: The function filter_var() can validate and sanitize data. This function filters a single
variable with a specified filter.
145. Which one of the following does not describe a validating filter?
a) Are used to allow or disallow specific characters in a string
b) Are used to validate user input
c) Strict format rules
d) Returns the expected type on success or FALSE on failure
View Answer
Answer: a
Explanation: Validate filter are used to validate user input, it have strict format rules and it
returns the expected type on success or FALSE on failure but ‘are used to allow or disallow
specific characters in a string’ describes sanitizing filters.

40 | P a g e
146. What will be the output of the following PHP code?

1. <?php
2. $var=300;
3. $int_options = array("options"=>array ("min_range"=>0, "max_range"=>256));
4. if (!filter_var($var, FILTER_VALIDATE_INT, $int_options))
5. echo("Integer is not valid");
6. else
7. echo("Integer is valid");
8. ?>
a) No output is returned
b) Integer is not valid
c) Integer is valid
d) Error
View Answer
Answer: b
Explanation: Since the integer is “300” it is not in the specified range, and the output of the code
above will be: “Integer is not valid”.
147. If the input variable is a string like this “http://www.saåånfoøøundry.com/”, the $url
variable after the sanitizing will look like?
a) http://www.saåånfoøøundry.com/
b) http://www.saaanfoooundry.com/
c) http://www.saånfoøundry.com/
d) https://www.sanfoundry.com/
View Answer
Answer: d
Explanation: Sanitize is nothing but take away invalid characters so therefore the invalid
characters like å and ø will be removed.
148. Which one of the following filter checks if the variable of the specified type exists?
a) filter_has_var
b) filter_var
c) filter_id
d) filter_var_array
View Answer
Answer: a
Explanation: The filter filter_has_var checks if the variable of the specified type exists. Whereas
the function filter_id() returns filter ID of a specified filter name. The function filter_var() can
validate and sanitize data. The function filter_var_array() can get multiple variables and it
optionally filters them.

41 | P a g e
149. What will be the output of the following PHP code?

1. <?php
2. $value = 'car';
3. $result = filter_var($value, FILTER_VALIDATE_BOOLEAN,
FILTER_NULL_ON_FAILURE);
4. ?>
a) FALSE
b) TRUE
c) NULL
d) ERROR
View Answer
Answer: c
Explanation: There is an undocumented filter flag for FILTER_VALIDATE_BOOLEAN. The
documentation implies that it will return NULL if the value doesn’t match the allowed true/false
values. However this doesn’t happen unless you give it the FILTER_NULL_ON_FAILURE
flag.
150. What will be the output of the following PHP code?

1. <?php
2. function convertSpace($string)
3. {
4. return str_replace("_", " ", $string);
5. }
6. $string = "Peter_is_a_great_guy!";
7. echo filter_var($string, FILTER_CALLBACK, array("options"=>"convertSpace"));
8. ?>
a) Peter_is_a_great_guy!
b) Peterisagreatguy!
c) Peter is a great guy!
d) Error
View Answer
Answer: c
Explanation: The code above converts all “_” to white spaces. Call the filter_var() function with
the FILTER_CALLBACK filter and an array containing our function.

42 | P a g e
151. What is the default type of ‘type’ attribute of <input> element?
a) Text
b) Password
c) Numerals
d) Special Characters
View Answer
Answer: a
Explanation: Text input type defines single line text field. Type is the attribute that displays type
of <input> elements. Its default type is text. It is supported by most of the browsers like Chrome,
Internet Explorer, Firefox, Opera. Syntax is: <form action=”jump.php”> Name:<input
type=”text” name=”name”> </form> A password field is defined by password input.
152. Which of the following is a new input attribute introduce by HTML5?
a) text
b) checkbox controls
c) submit buttons
d) date
View Answer
Answer: d
Explanation: HTML4 has attributes with <input> elements like radio buttons, Checkbox
controls, submit buttons, text input etc.
HTML5 has introduced new attributes like date, color, month, time, week, datetime-local, email,
number, range, tel, url, search etc.
153. How does the color attribute work?
a) Changes color of the text
b) Changes background color
c) The color picker is defined by it
d) Changes color of the text as well as background
View Answer
Answer: c
Explanation: color is the attribute of <input> element introduce by HTML5. It defines the color
picker i.e we can select a color of our choice from the color picker. Syntax is Select the color that
you want: <input type=”color” name=”favorite color”>
154. Which attribute is used for activation of JavaScript?
a) button
b) checkbox
c) url
d) submit
View Answer
Answer: a
Explanation: Input type button is used for the activation of JavaScript on the clicking of the
button. Its syntax is <input type=”button” value=”click” onclick=”source()”>. This will display a
button named click and when we click that button JavaScript function source() will be invoked.

43 | P a g e
155. Which attribute defines the file-select field?
a) file
b) checkbox
c) button
d) text
View Answer
Answer: a
Explanation: file input type defines a file-select field, also gives a “Browse” button for file
uploads. Syntax is <input type=”file” name=”image”>. Checkbox gives the facility to select one
or more than one options from the given choices. The button activates JavaScript code. The text
defines a single-line text field.
156. How image attribute works?
a) Sets an image background
b) Set an image as submit button
c) Set an image anywhere on the page
d) Bring default image to the page
View Answer
Answer: b
Explanation: the image input type set an image as submit button. The syntax is <input
type=”image” src=”imghj.gif” alt=”Submit”> this sets the image provided by url as the submit
button. Input type image sends the X and Y coordinates of click and hence the image is activated
by clicking the submit button.
157. month attribute defines ___________
a) the only month
b) month and year
c) date
d) date and time
View Answer
Answer: b
Explanation: month and year are defined by month attribute. It does not define the time zone.
The syntax is Anniversary (month and year) <input=”month” name=”anniversary month” >.,
date attribute defines the date, datetime-local defines date and time but no time zone.
158. week attribute defines ____________
a) week
b) year
c) week and year
d) week, month and year
View Answer
Answer: c
Explanation: week input type defines a week and year. It does not define the time zone. Syntax is
<form action=”ghu.php”> week: <input type=”week” name=”week and year”> <input
type=”submit”> </form>, this gives a selection box and display a calendar like chart from where
we can select a week and the year as well.

44 | P a g e
159. tel attribute is supported by the _________ browser.
a) Chrome
b) Safari
c) Opera
d) Internet Explorer
View Answer
Answer: b
Explanation: tel is the attribute which specifies field for telephone number. Syntax is <form
action=”hkjk.php”> Telephone number: <input type=”tel” name=”usertelephone”> <br> <input
type=”submit”> </form>, tel attribute is usually supported by newer versions like Safari 8.

160. Which attribute is not used on new forms?


a) size
b) text
c) name
d) maxlength
View Answer
Answer: a
Explanation: size attribute denotes the width of text input i.e measured by the number of
characters inputted. E.g. If we input value 3 then it will create a box of width enough to display
three characters. The user can enter more characters if they want. Syntax is <input type=”text”
name=”firstname” size=”12” maxlength=”30”>
161. Which of the following is not used with password attribute?
a) name
b) size
c) maxlength
d) min
View Answer
Answer: d
Explanation: password is the attribute that creates a text box which is similar to the single line
text input, but the characters are blocked out. They are hidden due to the privacy of the user. The
name attribute with a password set the name of the password input, size and maxlength attributes
define the size and maximum length of the text box which is to be used for the password.
162. Which element is used to create multi-line text input?
a) text
b) textarea
c) submit
d) radio button
View Answer
Answer: b
Explanation: For creating multi-line text input we use <textarea> element. This is not empty
element i.e. it requires both opening tag and closing tag. The cols attribute defines a width of the
text area. The row attributes the number of rows that the textarea can require.

45 | P a g e
163. Which attribute is not used for the radio type?
a) name
b) value
c) checked
d) selected
View Answer
Answer: d
Explanation: When we want to pick one option from the given many options we use radio type.
Name attribute sent the value of the option selected to the server. Value attribute indicates the
value that has been sent to the server for the selected option. The checked attribute indicates that
which value should be selected on the loading of the page.
164. Which attribute is used with <select> element?
a) multiple
b) selected
c) name
d) value
View Answer
Answer: a
Explanation: <select> element is used for drop down select box. Size attribute is used for
showing more than one option. For a selection of multiple options, we use multiple attributes. It
is a useful option to select multiple things at a time.
Syntax is
<form action=”jhi.php”> <select name=”fruits” size=”5” multiple=”multiple”>
165. Which of the following is not the form type for adding text?
a) Text input
b) Text area
c) Password input
d) Submit button
View Answer
Answer: d
Explanation: There are many types of form controls. Adding text, Submitting forms, Making
choices and Uploading files are some of them. For an adding text, we can use Text input, Text
area, and Password input. For making choices there are checkboxes, radio buttons, and drop-
down boxes.
166. In the processing of information, the server does not use the language _____
a) C#
b) JAVA
c) C++
d) VB.net
View Answer
Answer: c
Explanation: When we enter a new value through form it goes to the server for processing
information and this information is processed using languages C#, PHP, JAVA or VB.net. The
database can also store the information.

46 | P a g e
167. For creating single line text box for searching queries, we use the type ___________
a) placeholder
b) search
c) url
d) hidden
View Answer
Answer: b
Explanation: For creating a single line text box for searching queries we use the type=”search”.
In old browsers, it will be simply a single line text box. Safari adds across that clear search box
when we enter new data to search. It also rounds the corners on search input fields by default.

168. Form validation traditionally was performed by ___________


a) PHP
b) HTML
c) JavaScript
d) jQuery
View Answer
Answer: c
Explanation: Form validation is checking if the form has been filled correctly. Traditionally it
has been performed by JavaScript but now HTML5 is introducing validation. Hence browser
does all the work of validation. Validation reduces the amount of work for the server.
169. For grouping form controls we can use ___________
a) <legend>
b) <fieldset>
c) <label>
d) <select>
View Answer
Answer: b
Explanation: For grouping form controls together we use <fieldset> element. Fieldset is shown
with a line around edge. Appearance can be adjusted by CSS.
E.g. <fieldset> <legend> details </legend> <label> Name: <br/> <>input type=”text”
name=”name”/> </label> <br/> </fieldset>
170. Which one has the most potential for minification?
a) JavaScript
b) CSS
c) HTML
d) PHP
View Answer
Answer: a
Explanation: Among the four languages JavaScript, PHP, HTML and CSS, JavaScript has the
most potential for minification. In JavaScript whitespaces and comments are removed.
Windows-style line breaks (CRLF) is converted to UNIX-style breaks (LF). Moreover, variable
names can also be shortened.

47 | P a g e
171. YUI compressor is written in ____________
a) HTML
b) C++
c) C
d) Java
View Answer
Answer: d
Explanation: YUI compressor is one of the best compressor. It is a command-line minifier which
is written in Java. It can process CSS as well as JavaScript. It is simple to run it like-
$java –jar /usr/local/bin//yuicompressor-2.3.5/build/yuicompressor-2.3.5.jar input.js > output.js

172. Which compressor gives maximum GZIPPED compression?


a) YUI
b) JSMin
c) Packer
d) Closure(advanced)
View Answer
Answer: a
Explanation: YUI compressor gives maximum GZIPPED compression i.e. 21 out of 122. JSMin
gives 23 out of 122, Closure(simple) gives 21 out of 122, Closure(advanced) gives 18 out of 122,
Packer gives 23 out of 122. There is also redundancy due to GZIP compression.
173. CSSMin is written in ___________
a) C++
b) Java
c) PHP
d) C
View Answer
Answer: b
Explanation: CSSMin is written in Java. It preforms conversion of lowercase, ordering of
properties, replacement of names with numeric or hex equivalents. E.g. font-weight:bold can be
written as font-weight: 600, color: black to color: #000.
174. HTMLMinifier is written in ________
a) JavaScript
b) Java
c) C++
d) C
View Answer
Answer: a
Explanation: There are mainly two popular HTML minifier. HTMLMinifier and htmlcompressor
first are written in JavaScript. It is to be run via a web browser. Second is command-line Java
application. HTMLMinifier offers better levels of compression.

48 | P a g e
175. Which option is not available in HTMLMinifier?
a) remove attribute quotes
b) use the short doctype
c) remove empty elements
d) replace <strong> with <b>
View Answer
Answer: d
Explanation: There are many options available in HTMLMinifier like it removes comments, also
comments from CSS and JavaScript blocks, collapses whitespace, removes character data blocks
from JavaScript and CSS, Collapses Boolean attributes, removes redundant attributes, uses a
short doctype, removes empty elements, removes attribute quotes.
176. Each cell of the table can be represented by using __________
a) <tr>
b) <td>
c) <th>
d) <thead>
View Answer
Answer: b
Explanation: td stands for table data, we can represent each cell of the table by using <td>, at the
end we used </td> tag. But some browsers by default draw the lines around table. <tr> is used to
indicate start of every row i.e. it stands for table row. The header information is present in <th>
tag. <thead> tag contains the group of header.
177. For heading we can use ____________
a) <td>
b) <tr>
c) <thead>
d) <th>
View Answer
Answer: d
Explanation: <th> element is used for representing heading of column or a row. It works same as
<td> element. If shell has no content we can use <th> element also there. We can use scope
attribute for specifying the heading is for row or column. Usually content of <th> is represented
in bold. <thead> tag contains the group of header. <tr> is used to indicate start of every row i.e. it
stands for table row.
178. Headings of table lies inside ___________
a) <thead>
b) <tfoot>
c) <th>
d) <tbody>
View Answer
Answer: a
Explanation: Headings of the table lies inside <thead> element. Footer lies inside the <tfoot>
element. The body of the table lies inside <tbody> element. <th> is used for giving heading to a
row or a column. Every element must have closing tag also i.e. </thead>, </tfoot>, </tbody>

49 | P a g e
179. Which of the following is not the element associated with HTML table layout?
a) size
b) spanning
c) alignment
d) color
View Answer
Answer: d
Explanation: There are three elements in HTML table layout i.e. size, spanning and alignment.
Layout type can be achieved by setting Rows elements layout attribute to Fixed or Auto. Auto
attribute relies on browser compatibility whereas fixed layout relies on developer specification.

180. Which of the following element is not associated with a class attribute?
a) Row
b) <thead>
c) Column cell
d) Rows
View Answer
Answer: b
Explanation: Column cell, Row, and Rows are the container elements. They have a class
attribute with the help of this we can apply special styling. Table alignment is also controlled
style sheet classes. Text-align and vertical-align are the style attributes that align the content of
the table.
181. For adding caption to the table we use ____________
a) <caption>
b) <thead>
c) <th>
d) <tr>
View Answer
Answer: a
Explanation: For adding caption to the table we use <caption> tag. It should be used just below
the <table> tag.
Syntax is
<table>
<caption> Savings </caption>
<tr> <th> saving </th><th>loss</th> </tr>
<tr><td>$12</td>$45<td></td> </tr>
</table>.
<thead> tag contains the group of header. <tr> is used to indicate start of every row i.e. it stands
for table row. The header information is present in <th> tag.

50 | P a g e
182. border-spacing is given in _____________
a) pixels
b) cm
c) mm
d) inch
View Answer
Answer: a
Explanation: border-spacing and border-collapse are the two properties by which one can set the
border and its styling in a table. We give its value in pixels.
table { border-collapse: collapse; border-spacing: 14px } th, td{ border: 12 px solid red;
padding: 20px 13px; }
183. Borders can’t be applied on ________________
a) <th>
b) <td>
c) <tr>
d) <thead>
View Answer
Answer: c
Explanation: Borders can’t be applied on <tr> elements. It can’t be applied on table structural
elements. For setting borders with <tr> element, border-collapse property should be set to
collapse.
Syntax is
table {border-collapse: collapse;}
th, td{border-bottom: 2px dotted red; }
tfoot tr:last-child td{border-bottom: 9 px;}
184. Which attribute defines numbers of columns in a group?
a) width=multi-length[CN].
b) span=number[CN].
c) scope=scope-name[CN].
d) headers=idrefs[CS].
View Answer
Answer: b
Explanation: span=number[CN] attribute’s value must be an integer and greater than 0. It
specifies the number of columns in a group. When span attribute is not in use, colgroup defines a
single column group containing one column. width=multi-length[CN] specifies default width of
for every column. scope=scope-name[CN] specifies set of data cells for which going header cell
gives header information. The headers=idrefs[CN] provides list of header cells that gives header
information.

51 | P a g e
185. Which of the following does not specify a column width?
a) Fixed
b) Percentage
c) Proportional
d) Pixels
View Answer
Answer: d
Explanation: We can specify column width in three ways i.e. Percentage, Fixed, Proportional.
Fixed width is given in pixels. Percentage specification is the percentage of horizontal space
availability in the table. The proportional specification is the portions of fixed horizontal space
required for the table.
186. Scope attribute can’t have the value __________
a) row
b) rowgroup
c) col
d) <head>
View Answer
Answer: d
Explanation: scope attribute defines a set of data cell. It is used in place of headers. This attribute
can have one of the value among rowgroup, row, colgroup, col, rowgroup, and colgroup provides
information of header cell of the corresponding row and column groups.
187. Which of the following is not the value for frame attribute?
a) above
b) void
c) none
d) box
View Answer
Answer: c
Explanation: Frame attribute gives information about which sides of the frame surrounding that
table will be visible. The values that this attribute can take are lhs, rhs, box, border, vsides,
hsides, below, above, void.
188. Which of the following is not the value for rules attribute?
a) vsides
b) rows
c) all
d) groups
View Answer
Answer: a
Explanation: The rules which will appear between cells of the table is specified by this attribute.
It can take the values groups, none, rows, all and cols. None is the default value, rows are for
appearance between rows only and cols is for columns only.

52 | P a g e
189. Which of the following is not the value for align attribute?
a) justify
b) char
c) middle
d) left
View Answer
Answer: c
Explanation: align attribute is the alignment of data and for justification of text in the cell. It can
take the values left, right, justify, center, char. Justify is for double justifying the text, char is for
aligning text around a particular character.

190. valign attribute does not take the value __________________


a) justify
b) middle
c) baseline
d) bottom
View Answer
Answer: a
Explanation: valign attribute is for specifying the vertical position of the data in a cell. It can take
the values middle, top, baseline, bottom, Top is for the top of the cell’s data, middle is for the
centered data, bottom is for the bottom of the cell, first text line occurs on the baseline which is
common to all the cells.

191.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
View Answer
Answer: d
PHP required that MySQL client library be installed on the server from which PHP was
communicating with MySQL, whether the MySQL server also happened to reside locally or
elsewhere. PHP 5.3 removes this problem by introducing MySQL Native Driver.

192.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
View Answer
Answer: A

53 | P a g e
Also make sure that extension_dir directive points to the appropriate directory.

193.Which one of the following databases has PHP supported almost since the beginning?

A. Oracle Database
B. SQL
C. SQL+
D. MySQL
View Answer
Answer: D

194.The updated MySQL extension released with PHP 5 is typically referred to as..

A. MySQL
B. mysql
C. mysqli
D. mysqly
View Answer
Answer: C
The updated MySQL extension with PHP 5 is known as MySQL and typically referred to as
mysqli.

195.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);
View Answer
Answer: A

196.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()
View Answer
Answer: B

54 | P a g e
197. If there is no error, then what will the error() method return?

A. TRUE
B. FALSE
C. Empty String
D. 0
View Answer
Answer: C

198.Which method returns the error code generated from the execution of the last MySQL
function?

A. errno()
B. errnumber()
C. errorno()
D. errornumber()
View Answer
Answer: A
Error numbers are often used in lieu of natural-language message to ease software
internationalization efforts and allow for customization of error messages.

199.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’);
View Answer
Answer: D

200.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()
View Answer
Answer: C

55 | P a g e
The mysqli extension includes a few features that can be used to capture error messages or
alternatively you can use exceptions.

201.Which version of MySQL introduced the prepared statements?

A. MySQL 4.0
B. MySQL 4.1
C. MySQL 4.2
D. MySQL 4.3
View Answer
Answer: B

When the query() method is looped repeatedly it comes at a cost of both overhead, because of the
need to repeatedly parsing of the almost identical query for validity, and coding convenience,
because of the need to repeatedly reconfigure the query using the new values for each iteration.
To help resolve the issues incurred by repeatedly executed queries, MySQL introduced prepared
statements.

203.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()
View Answer
Answer: A

Once the statement has been prepared, it needs to be executed. Exactly when it’s executed
depends upon whether you want to work with bound parameters or bound results. In the case of
bound parameters, you’d execute the statement after the parameters have been bound with the
bind_param() method.

204.Which one of the following methods is used to recuperating prepared statements resources?

A. end()
B. finish()
C. final()
D. close()

View Answer
Answer: D
Once you’ve finished using a prepared statement, the resources it requires can be recuperated
with the close() method.

56 | P a g e
205.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. row()
View Answer
Answer: C

Its prototype follows:


class mysqli{
boolean fetch()
}

206.Which method rolls back the present transaction?

A. commit()
B. undo()
C. back()
D. rollback()
View Answer
Answer: D

Its prototype follows:


class mysqli{
boolean rollback()
}

207.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. new_rows()

View Answer
Answer: B
The method num_rows() is only useful for determining the number of rows retrieved by a
SELECT query. But to retrieve the number of rows affected by INSERT, UPDATE, or DELETE
query, use affected_rows().

57 | P a g e
208.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. fetch_array() and fetch_column()
View Answer
Answer: C

Their prototype is as follows-


calss mysqli_result{
mixed fetch_array ([int resulttype])
}
calss mysqli_result{
mixed fetch_row()
}

209.Which one of the following methods recuperates any memory consumed by a result set?

A. destroy()
B. remover()
C. alloc()
D. free()
View Answer
Answer: D
Once this method is executed, the result set is no longer available.

210.Which one of the following methods is responsible for sending the query to the database?

A. query()
B. send_query()
C. sendquery()
D. query_send()
View Answer
Answer: A

Its prototype looks like-


class mysqli{
mixed query(string query [, int resultmode])
}

58 | P a g e
211.Which one of the following statements should be used to include a file?

A. #include ‘filename’;
B. include ‘filename’;

View Answer
Answer: B

An example of this-
#include 'mysql.connect.php';
//begin database selection and queries.
?>

HTML FORM MCQS

1. Which two predefined variables are used to retrieve information from forms?

A. $GET & $SET

B. $_GET & $_SET

C. $__GET & $__SET

D. GET & SET

Answer : B

2. The attack which involves the insertion of malicious code into a page frequented by other users is
known as..

A. basic sql injection

B. advanced sql injection

C. cross-site scripting

D. scripting

Answer : C

3. When you use the $_GET variable to collect data, the data is visible to..

A. none

B. only you

59 | P a g e
C. everyone

D. selected few

Answer : C

4. When you use the $_POST variable to collect data, the data is visible to..

A. none

B. only you

C. everyone

D. selected few

Answer : B

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

A. $BOTH

B. $_BOTH

C. $REQUEST

D. $_REQUEST

Answer : D

6. Which one of the following should not be used while sending passwords or other sensitive
information?

A. GET

B. POST

C. REQUEST

D. NEXT

Answer : A

7. Which function is used to remove all HTML tags from a string passed to a form?

A. remove_tags()

B. strip_tags()

C. tags_strip()

60 | P a g e
D. tags_remove()

Answer : B

8. To validate an e-mail address, which flag is to be passed to the function filter_var()?

A. FILTER_VALIDATE_EMAIL

B. FILTER_VALIDATE_MAIL

C. VALIDATE_EMAIL

D. VALIDATE_MAIL

Answer : A

9. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?

A. 5

B. 6

C. 7

D. 8

Answer : C

PHP FILE SYSTEM MCQS

1. The filesize() function returns the file size in ___________

a) bits

b) bytes

c) kilobytes

d) gigabytes

Answer : B

61 | P a g e
2. Which one of the following PHP function is used to determine a file’s last access time?

a) fileltime()

b) filectime()

c) fileatime()

d) filetime()

Answer : C

3. Which one of the following function is capable of reading a file into an array?

a) file()

b) arrfile()

c) arr_file()

d) file_arr()

Answer : A

4. Which one of the following function is capable of reading a file into a string variable?

a) file_contents()

b) file_get_contents()

c) file_content()

d) file_get_content()

Answer : B

5. Which one of the following function is capable of reading a specific number of characters from a file?

a) fgets()

b) fget()

c) fileget()

d) filegets()

Answer : A

6. Which one of the following function operates similarly to fgets(), except that it also strips any HTML
and PHP tags form the input?

62 | P a g e
a) fgetsh()

b) fgetsp()

c) fgetsa()

d) fgetss()

Answer : D

7. Which one of the following function outputs the contents of a string variable to the specified
resource?

a) filewrite()

b) fwrite()

c) filewrites()

d) fwrites()

Answer : B

8. Which function sets the file filename last-modified and last-accessed times?

a) sets()

b) set()

c) touch()

d) touched()

Answer : C

9. Which function is useful when you want to output the executed command result?

a) out_cmm()

b) out_system()

c) cmm()

d) system()

Answer : D

10. Which one of the following function reads a directory into an Array?

a) scandir()

63 | P a g e
b) readdir()

c) scandirectory()

d) readdirectory()

Answer : A

1. Which two predefined variables are used to retrieve information from forms?

 A. $GET & $SET

 B. $_GET & $_SET

 C. $__GET & $__SET

 D. GET & SET

ANSWER: Option B

2. The attack which involves the insertion of malicious code into a page frequented by other users is known
as..

 A. basic sql injection

 B. advanced sql injection

 C. cross-site scripting

 D. scripting

ANSWER: Option C

3. When you use the $_GET variable to collect data, the data is visible to..

 A. none

 B. only you

 C. everyone

 D. selected few

ANSWER: OPTION C

4. When you use the $_POST variable to collect data, the data is visible to..

 A. none

 B. only you

 C. everyone

 D. selected few

Answer: Option B
Explanation:

64 | P a g e
The POST method, data is invisible to others

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

 A. $BOTH

 B. $_BOTH

 C. $REQUEST

 D. $_REQUEST

Answer: Option D

6. Which one of the following should not be used while sending passwords or other sensitive information?

 A. GET

 B. POST

 C. REQUEST

 D. NEXT

Answer: Option A
Explanation:
Because the data is visible to everyone.

7. Which function is used to remove all HTML tags from a string passed to a form?

 A. remove_tags()

 B. strip_tags()

 C. tags_strip()

 D. tags_remove()

Answer: Option B

8. To validate an e-mail address, which flag is to be passed to the function filter_var()?

 A. FILTER_VALIDATE_EMAIL

 B. FILTER_VALIDATE_MAIL

 C. VALIDATE_EMAIL

 D. VALIDATE_MAIL

Answer: Option A

9. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?

 A. 5

65 | P a g e
 B. 6

 C. 7

 D. 8

Answer: Option C
Explanation:
There are seven validation filters. They are FILTER_VALIDATE_EMAIL, FILTER_VALIDATE_BOOLEAN,
FILTER_VALIDATE_FLOAT, FILTER_VALIDATE_INT, FILTER_VALIDATE_IP, FILTER_VALIDATE_REGEXP,
FILTER_VALIDATE_URL.

10.For ceating a drop down list in HTML forms which element is suitable?
A. <list>
B. <dropdown>
C. <select>
D. All of the above

ANSWER: OPTION C

11. Choose the correct option.

A. HTML form elements are used for taking user input.


B. HTML form elements are defined inside <for> tag.
C. HTML form elements can be of different types.
D. All of these.

ANSWER: OPTION D
Explanation: All the above three statements hold true for forms in HTML.

12. Which one of the following is a form element?

A. text box.
B. radio button.
C. submit button.
D. All of these.

ANSWER: OPTION D
Explanation: All of these are the types of form element.

13. Which one of the following is incorrect?

A. <label> tag in HTML is used for creating a tag for form elements.
B. <label> can be used to increase the clickable area of buttons
C. id attribute is used with <label> to increase the clickable area of form elements
D. None of the above

ANSWER: OPTION C

66 | P a g e
Explanation: attribute for is used with <label> for increasing the clickable area of form
elements.

14. Choose the incorrect option.

A. radio button allows to choose only one option from the given options.
B. default option can be chosen using attribute "selected" in radio button
C. default option can be chosen using attribute "checked" in radio button
D. checkbox allows to choose one or more than one options from the given options .

ANSWER: OPTION B

Explanation: "selected" is used to set an option as default in the radio button.

15. Choose the incorrect option.

A. action attribute is used inside starting tag of form.


B. With the use of action, we can redirect to a page once submit button is clicked.
C. <form action:"home.php"> redirects to the page home.php
D. None of the above

ANSWER: OPTION C

Explanation: Correct way of using action attribute is <form action="home.php">

16.Choose the correct option.

A. Use of method attribute determines by which method the datas in the form will be
submitted.
B. Method can be POST or GET.
C. Default method in HTML is GET.
D. All of the above

ANSWER: OPTION D
Explanation: All three options are true with reference to the GET method in HTML.

17. Which one of the following does not hold true regarding GET method in HTML?

A. Use of GET method in HTML is more secured.


B. Use of GET method enables us to bookmark the page.
C. GET has size limitation.
D. None of the above

ANSWER: OPTION A

67 | P a g e
Explanation: The use of the GET method is not secured as data sent will be visible in the URL.

18. Which one of the following does not hold true regarding POST method in HTML?

A. Use of POST method in HTML is more secured.


B. Use of POST method enables us to bookmark the page.
C. POST has no size limitation.
D. None of these.

ANSWER: OPTION B
Explanation: The use of POST method for form submission does not allow to bookmark the
page.

19. Which of the following tag is used for drop down list?

A. <select>
B. <text>
C. <textarea>
D. <dropdown>

ANSWER: OPTION A

20. How more than one option can be selected in drop down?

A. Use of multiple attribute inside <option> tag.


B. Use of multiple attribute inside <select> tag.
C. use of multiple attribute inside <text> tag.
D. It is not possible to select more than one option in drop down.

ANSWER: OPTION B
Explanation: By the use of multiple attributes inside opening tag of <select>, more than one
option can be selected in dropdown.

21. What will be the value of the variable $input in the following PHP code?

1. <?php
2. $input = "Swapna<td>Lawrence</td>you are really<i>pretty</i>!";
3. $input = strip_tags($input,"<i></i>");
4. echo $input;
5. ?>
a)Swapna Lawrence you are really pretty!
b) Swapna <td>Lawrence</td> you are really<i>pretty</i>!
c) Swapna <td>Lawrence</td> you are really pretty!
d) Swapna Lawrence you are really<i>pretty</i>!

ANSWER: OPTION D
Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially
wreak havoc on a page.

68 | P a g e
22. How do you get information from a form that is submitted using the "get" method?
A. $_GET[];
B.Request.Form;
C. Request.QueryString;

ANSWER: OPTION A

23. When using the POST method, variables are displayed in the URL:
A.TRUE
B.FALSE

ANSWER: B

24. For accession global variables anywhere from the script, PHP uses
A. Get and Post methods
B. Functions
C. Superglobals Arrays
D. None of them

ANSWER: OPTION C

25. Which methods passes the arguments from one page to the next as a part of uniform
resource indicator?
A. Post method
B. Get method
C.Parsing method
D.None of them

ANSWER: OPTION B

26. There are how many main methods for passing information between web pages and server
A. 2 methods
B. 3 methods
C. 4 methods
D. A lot of methods

ANSWER: OPTION C

27.$GLOBALS,$_SERVER,$_REQUEST,$_POST,$_GET,$_FILES,$_COOKIE,$_SESSION all are


example of
A. Super array
B. Global variables
C. Local variables
D. None of them

ANSWER: OPTION B

69 | P a g e
28. Which method is not suitable for logins because it stores the data in client browsers
memory?
A. Post method
B. Put method
C. Get method
D. Set method

ANSWER: OPTION C

29. Every Get methods submission is recorded in the


A. Script
B. Web server
C. History
D. All of them

ANSWER: OPTION B

30. In post method the results at a given moment cannot be


A. Saved
B. Move
C. Bookmarked
D. Deleted

ANSWER: OPTION C

1. Choose the correct option.

A. HTML form elements are used for taking user input.


B. HTML form elements are defined inside <for> tag.
C. HTML form elements can be of different types.
D. All of these.

Ans : D

Explanation: All the above three statements hold true for forms in HTML.

2. Which one of the following is a form element?

A. text box.
B. radio button.
C. submit button.
D. All of these.

70 | P a g e
Ans : D

Explanation: All of these are the types of form element.

3. Which one of the following is incorrect?

A. <label> tag in HTML is used for creating a tag for form elements.
B. <label> can be used to increase the clickable area of buttons
C. id attribute is used with <label> to increase the clickable area of form elements
D. None of the above

Ans : C

Explanation: attribute for is used with <label> for increasing the clickable area of form elements.

4. Choose the incorrect option.

A. radio button allows to choose only one option from the given options.
B. default option can be chosen using attribute "selected" in radio button
C. default option can be chosen using attribute "checked" in radio button
D. checkbox allows to choose one or more than one options from the given options.

Ans : B

Explanation: "selected" is used to set an option as default in the radio button.

5. Choose the incorrect option.

A. action attribute is used inside starting tag of form.


B. With the use of action, we can redirect to a page once submit button is clicked.
C. <form action:"home.php"> redirects to the page home.php
D. None of the above

Ans : C

Explanation: Correct way of using action attribute is <form action="home.php">

6. Choose the correct option.

71 | P a g e
A. Use of method attribute determines by which method the datas in the form will be submitted.
B. Method can be POST or GET.
C. Default method in HTML is GET.
D. All of the above

Ans : D

Explanation: All three options are true with reference to the GET method in HTML.

7. Which one of the following does not hold true regarding GET method in HTML?

A. Use of GET method in HTML is more secured.


B. Use of GET method enables us to bookmark the page.
C. GET has size limitation.
D. None of the above

Ans : A

Explanation: The use of the GET method is not secured as data sent will be visible in the URL.

8. Which one of the following does not hold true regarding POST method in HTML?

A. Use of POST method in HTML is more secured.


B. Use of POST method enables us to bookmark the page.
C. POST has no size limitation.
D. None of these.

Ans : B

Explanation: The use of POST method for form submission does not allow to bookmark the
page.

9. Which of the following tag is used for drop down list?

A. <select>
B. <text>
C. <textarea>
D. <dropdown>

Ans : A

72 | P a g e
Explanation: <select> is used for dropdown list.

10. How more than one option can be selected in drop down?

A. Use of multiple attribute inside <option> tag.


B. Use of multiple attribute inside <select> tag.
C. use of multiple attribute inside <text> tag.
D. It is not possible to select more than one option in drop down.

Ans : B

Explanation: By the use of multiple attributes inside opening tag of <select>, more than one
option can be selected in dropdown

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “File System and
PHP”.

1. The filesize() function returns the file size in ___________


a) bits
b) bytes
c) kilobytes
d) gigabytes

Answer: b
Explanation: The function filesize() returns the size of the specified file and it returns the file size
in bytes on success or FALSE on failure.

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

Answer: c
Explanation: The fileatime() function returns a file’s last access time in Unix timestamp format
or FALSE on error.

73 | P a g e
3. Which one of the following function is capable of reading a file into an array?
a) file()
b) arrfile()
c) arr_file()
d) file_arr()

Answer: a
Explanation: The function file() will read the entire file into an array.

4. Which one of the following function is capable of reading a file into a string variable?
a) file_contents()
b) file_get_contents()
c) file_content()
d) file_get_content()

Answer: b
Explanation: The function file_get_contents() reads a file into a string. This is the preferred way
to read the contents of a file into a string as it will use memory mapping techniques.

5. Which one of the following function is capable of reading a specific number of characters
from a file?
a) fgets()
b) fget()
c) fileget()
d) filegets()

Answer: a
Explanation: The function fgets() will return a line from an open file. This stops returning on a
new line, at the specified length, or at EOF, whichever comes first. Its prototype is string
fgets(resource handle [, int length]). If the optional length parameter is omitted, 1024 character is
assumed.

6. Which one of the following function operates similarly to fgets(), except that it also strips any
HTML and PHP tags form the input?
a) fgetsh()
b) fgetsp()
c) fgetsa()
d) fgetss()

74 | P a g e
Answer: d
Explanation: The function fgetss() returns a line, with HTML and PHP tags removed, from an
open file. This function operates similarly to fgets(), except that it also strips any HTML and
PHP tags form the input.

7. Which one of the following function outputs the contents of a string variable to the specified
resource?
a) filewrite()
b) fwrite()
c) filewrites()
d) fwrites()

Answer: b
Explanation: The function fwrite() writes to an open file. This will stop at the end of the file or
when it reaches the specified length, whichever comes first.

8. Which function sets the file filename last-modified and last-accessed times?
a) sets()
b) set()
c) touch()
d) touched()

Answer: c
Explanation: The function touch() will set the access and modification time of the specified file.
Syntax is touch(filename, time, atime).
9. Which function is useful when you want to output the executed command result?
a) out_cmm()
b) out_system()
c) cmm()
d) system()

Answer: d
Explanation: The function system() in PHP is same as the C version of the function as in that it
executes the given command and outputs the result. This function also tries to automatically
flush the web server’s output buffer after each line of output if PHP is running as a server
module.

10. Which one of the following function reads a directory into an Array?
a) scandir()
b) readdir()
c) scandirectory()
d) readdirectory()

75 | P a g e
Answer: a
Explanation: It returns an array consisting of files and directories found in directory or returns
FALSE on error.

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Uploading Files
with PHP”.

1. Which directive determines whether PHP scripts on the server can accept file uploads?
a) file_uploads
b) file_upload
c) file_input
d) file_intake

Answer: a
Explanation: With PHP, it is easy to upload files to the server. We need to ensure that PHP is
configured to allow file uploads. In the “php.ini” file, search for the file_uploads directive, and
set it to On. By default, its value is on.

2. Which of the following directive determines the maximum amount of time that a PHP script
will spend attempting to parse input before registering a fatal error?
a) max_take_time
b) max_intake_time
c) max_input_time
d) max_parse_time

Answer: c
Explanation: This is relevant because particularly large files can take some time to upload,
eclipsing the time set by this directive.

3. What is the default value of max_input_time directive?


a) 30 seconds
b) 60 seconds
c) 120 seconds
d) 1 second

76 | P a g e
Answer: b
Explanation: The default value of the max_input_time directive is 60 seconds.

4. Since which version of PHP was the directive max_file_limit available.


a) PHP 5.2.1
b) PHP 5.2.2
c) PHP 5.2.12
d) PHP 5.2.21

Answer: c
Explanation: The max_file_limit directive sets an upper limit on the number of files which can
be simultaneously uploaded.

5. What is the default value of the directive max_file_limit?


a) 10 files
b) 15 files
c) 20 files
d) 25 files

Answer: c
Explanation: The default value of the directive max_file_limit is 20 files.

6. Which directive sets a maximum allowable amount of memory in megabytes that a script can
allow?
a) max_size
b) post_max_size
c) max_memory_limit
d) memory_limit

Answer: d
Explanation: Its default value is 16M.

7. If you want to temporarily store uploaded files in the /tmp/phpuploads/ directory, which one of
the following statement will you use?
a) upload_tmp_dir “/tmp/phpuploads/ directory”
b) upload_dir “/tmp/phpuploads/ directory”

77 | P a g e
c) upload_temp_dir “/tmp/phpuploads/ directory”
d) upload_temp_director “/tmp/phpuploads/ directory”

Answer: a
Explanation: Anyone can temporarily store uploaded files on the given directory. One cannot
change upload_tmp_dir at the runtime. By the time a script runs, the upload process has already
occurred.

8. Which superglobal stores a variety of information pertinent to a file uploaded to the server via
a PHP script?
a) $_FILE Array
b) $_FILES Array
c) $_FILES_UPLOADED Array
d) $_FILE_UPLOADED Array

Answer: b
Explanation: The superglobal $_FILES is a two-dimensional associative global array of items
which are being uploaded by via HTTP POST method and holds the attributes of files.

9. How many items are available in the $_FILES array?


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

Answer: d
Explanation: $_FILEs[‘userfile’][‘error’], $_FILEs[‘userfile’][‘name’],
$_FILEs[‘userfile’][‘size’], $_FILEs[‘userfile’][‘tmp_name’], $_FILEs[‘userfile’][‘type’] are the
five items in the array.

10. Which function is used to determine whether a file was uploaded?


a) is_file_uploaded()
b) is_uploaded_file()
c) file_uploaded(“filename”)
d) uploaded_file(“filename”)

Answer: b
Explanation: The function is_uploaded_file() checks whether the specified file is uploaded via
HTTP POST. The syntax is is_uploaded_file(file).

78 | P a g e
This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Image Uploading
Ability”.

1. Before you can start processing images with PHP, you must first add the ability to upload
images to your administrative form on ________
a) .htaccess
b) function.inc.php
c) index.php
d) admin.php

Answer: d
Explanation: To do this, you’ need to add a file upload input to your administrative form.

2. When you’re uploading files you need to set the enctype of the form to __________
a) text
b) text/file
c) multipart/form-data
d) multimedia/form-data

Answer: c
Explanation: Set the enctype of the form to multipart/form-data, which can accept files and
standard form values.

3. To check whether a file was uploaded, you look in the _______ superglobal array.
a) $_FILES
b) $_DOCS
c) $_DOCUMENTS
d) $_FOLDERS

Answer: a
Explanation: Whenever a file is uploaded via an HTML form, that file is stored in temporary
memory and information about the file is passed in the $_FILES superglobal.

4. To make the ImageHandler class portable you should create a separate file for it called
__________
a) imagehandler.inc.php
b) images.inc.php

79 | P a g e
c) handler.inc.php
d) imghandler.inc.php

Answer: b
Explanation: You save this file in the inc folder (full path:
/xampp/htdocs/simple_blog/inc/images.inc.php).

5. DocBlocks are indicated by opening a comment using _________


a) /*
b) //*
c) /**
d) /*/

Answer: c
Explanation: This is a special comment that provides information about a class, property, or
method.

6. To process the file, you need to break the array from $_FILES into individual values. You can
do this using the ________ function.
a) divide()
b) list()
c) break()
d) indi()

Answer: b
Explanation: The list() function allows you to create named variables for each array index as a
comma-separated list.

7. Before you try to process the file, you need to make sure that your $err value is equivalent to
_________
a) UPLOAD_ERR_OK
b) UPLOAD_NO_ERR
c) UPLOAD_ERR_NO_OK
d) UPLOAD_ERR

Answer: a
Explanation: When you’re dealing with files uploaded through an HTML form, you have access
to a special constant called UPLOAD_ERR_OK that tells you whether a file uploaded
successfully.

80 | P a g e
8. You use the $_SERVER superglobal and your _______ property to create your path to check.
a) $load_dir
b) $load
c) $save
d) $save_dir

Answer: d
Explanation: // Determines the path to check
$path = $_SERVER['DOCUMENT_ROOT'] . $this->save_dir;

9. Which function do you have to use to check whether the $path you’ve stored exists?
a) path_dir()
b) path()
c) is_dir()
d) path_dir()

Answer: c
Explanation: If the path exists, is_dir() returns TRUE; otherwise, it returns FALSE.

10. Which one of the following is true about the following line – $obj = new
ImageHandler(‘/images/’, array(400, 300));?
a) This snippet sets the maximum dimensions allowed to 400 pixels wide by 300 pixels high
b) This snippet sets the minimum dimensions allowed to 300 pixels wide by 400 pixels high
c) This snippet sets the minimum dimensions allowed to 400 pixels wide by 300 pixels high
d) This snippet sets the maximum dimensions allowed to 300 pixels wide by 400 pixels high

Answer: a
Explanation: If you needed to change the size of your images, you can change the dimensions
using the above instantiation of ImageHandler.

81 | P a g e
MODULE -4

SESSION AND COOKIE

1>In PHP, cookies are set by using the

A. setcookie ( ) function
B. set ( ) function
C. cookie_set ( ) function
D. None of them

Ans: setcookie ( ) function

2>Name, value, expire, patrh, httponly, domain, secure all of these are arguments
of

A. session ( ) function
B. setcookie ( ) function
C. reset_cookie ( ) function
D. None of them

Ans: setcookie()function

3> The secure ( ) argument in setcookie function returns result

A. In integer form
B. In string form
C. In boolean form
D. None of them

Ans:In Boolean form

4> In PHP4.1 and later versions, the cookies name/value pair are added to the
A. Superglobal array
B. $_COOKIE
C. Global function
D. Both A and B

ans: Both A and B

5> When a session ia active, PHP provides a special constant called

A. SID
B. CID
C. DID
D. None of them

Ans:SID

6>If you want PHP to transparently handle passing session variables for you when
cookies are not available, you have to configure

A. enable-trans-sid option
B. enable-track-vars option
C. disable-tans-vars option
D. Both A and B

Ans:Both A and B

7> A special kind of a file that is located in the filesystem of your browser and can
be read and write from the web server, is calls as

A. Session
B. Cookies
C. Script
D. All of them

Ans:Script
8>Using $_SESSION, $HTTP_SESSION_VARS functions can be dangerous, so
that you can use

A. session_destroy ( )
B. session_unset ( )
C. set ( )
D. None of them

Ans:session_unset()

9>In PHP, cookies are set by using the

A. setcookie ( ) function
B. set ( ) function
C. cookie_set ( ) function
D. None of them

Ans:setcookie() function

10>Which one of the following is the very first task executed by a session enabled
page?
a) Delete the previous session
b) Start a new session
c) Check whether a valid session exists
d) Handle the session

Ans:c

11> How many ways can a session data be stored?


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

Ans:b
12>Which directive determines how the session information will be stored?
a) save_data
b) session.save
c) session.save_data
d) session.save_handler

Ans:d

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

Ans:a

14>If session.use_cookie is set to 0, this results in use of _____________


a) Session
b) Cookie
c) URL rewriting
d) Nothing happens

Ans:c

15>If the directive session.cookie_lifetime is set to 3600, the cookie will live until
____________
a) 3600 sec
b) 3600 min
c) 3600 hrs
d) the browser is restarted

Ans:a

16>Neglecting to set which of the following cookie will result in the cookie’s domain
being set to the host name of the server which generated it.
a) session.domain
b) session.path
c) session.cookie_path
d) session.cookie_domain

Ans:d

17>What is the default number of seconds that cached session pages are made
available before the new pages are created?
a) 360
b) 180
c) 3600
d) 1800

Ans:b

18> What is the default time(in seconds) for which session data is considered valid?
a) 1800
b) 3600
c) 1440
d) 1540

Ans:c

19> Which one of the following function is used to start a session?


a) start_session()
b) session_start()
c) session_begin()
d) begin_session()

Ans:b

20>Which function is used to erase all session variables stored in the current session?
a) session_destroy()
b) session_change()
c) session_remove()
d) session_unset()

Ans:d

21>What will the function session_id() return is no parameter is passed?


a) Current Session Identification Number
b) Previous Session Identification Number
c) Last Session Identification Number
d) Error

Ans:a

22>Which one of the following statements should you use to set the session username to
Nachi?
a) $SESSION[‘username’] = “Nachi”;
b) $_SESSION[‘username’] = “Nachi”;
c) session_start(“nachi”);
d) $SESSION_START[“username”] = “Nachi”;

Ans:b

23>What will be the output of the following PHP code? (Say your previous session username was
nachi.)

1. unset($_SESSION['username']);
2. printf("Username now set to: %s", $_SESSION['username']);

a) Username now set to: nachi


b) Username now set to: System
c) Username now set to:
d) Error

Ans:c
24>An attacker somehow obtains an unsuspecting user’s SID and then using it to
impersonate the user in order to gain potentially sensitive information. This attack is known
as __________
a) session-fixation
b) session-fixing
c) session-hijack
d) session-copy

Ans:a

25> Which parameter determines whether the old session file will also be deleted when the
session ID is regenerated?
a) delete_old_file
b) delete_old_session
c) delete_old_session_file
d) delete_session_file

Ans:b

26>Which function effectively deletes all sessions that have expired?


a) session_delete()
b) session_destroy()
c) session_garbage_collect()
d) SessionHandler::gc

Ans:d

27> Which function is used to transform PHP’s session-handler behavior into that defined
by your custom handler?
a) session_set_save()
b) session_set_save_handler()
c) Session_handler()
d) session_save_handler()
Ans:b

28>The session_start() function must appear _________


a) after the html tag
b) after the body tag
c) before the body tag
d) before the html tag

Ans:d

29>What is the return type of session_set_save_handler() function?


a) boolean
b) integer
c) float
d) character

Ans:a

Session(PHP)

1.Which one of the following is the very first task executed by a session enabled page?

a) Delete the previous session

b) Start a new session

c) Check whether a valid session exists

d) Handle the session

Answer:-C

Answer: c
Explanation: The session variables are set with the PHP global variable which is $_SESSION. The very first
task executed by a session enabled page is Check whether a valid session exists.

2. How many ways can a session data be stored?

a) 3

b) 4

c) 5

d) 6

Answer: b

Explanation: Within flat files(files), within volatile memory(mm), using the SQLite database(sqlite), or
through user defined functions(user).

3. Which directive determines how the session information will be stored?

a) save_data

b) session.save

c) session.save_data

d) session.save_handler

Answer: d

Explanation: The class SessionHandler is used to wrap whatever internal save handler is set as defined
by the session.save_handler configuration directive which is usually files by default.

4. Which one of the following is the default PHP session name?

a) PHPSESSID

b) PHPSESID

c) PHPSESSIONID

d) PHPIDSESS

Answer: a

Explanation: You can change this name by using the session.name directive.
5. If session.use_cookie is set to 0, this results in use of _____

a) Session

b) Cookie

c) URL rewriting

d) Nothing happens

Answer: c

Explanation: The URL rewriting allows to completely separate the URL from the resource. URL rewriting
can turn unsightly URLs into nice ones with a lot less agony and expense than picking a good domain
name. It enables to fill out your URLs with friendly, readable keywords without affecting the underlying
structure of pages.

6. If the directive session.cookie_lifetime is set to 3600, the cookie will live until ____

a) 3600 sec

b) 3600 min

c) 3600 hrs

d) the browser is restarted

Answer: a

Explanation: The lifetime is specified in seconds, so if the cookie should live 1 hour, this directive should
be set to 3600.

7. Neglecting to set which of the following cookie will result in the cookie’s domain being set to the host
name of the server which generated it.

a) session.domain

b) session.path

c) session.cookie_path

d) session.cookie_domain

Answer: d

Explanation: The directive session.cookie_domain determines the domain for which the cookie is valid.
8. What is the default number of seconds that cached session pages are made available before the new
pages are created?

a) 360

b) 180

c) 3600

d) 1800

Answer: b

Explanation: The directive which determines this is session.cache_expire.

9. What is the default time(in seconds) for which session data is considered valid?

a) 1800

b) 3600

c) 1440

d) 1540

Answer: c

Explanation: The session.gc_maxlifetime directive determines this duration. It can be set to any required
value.

10. Which one of the following function is used to start a session?

a) start_session()

b) session_start()
c) session_begin()

d) begin_session()

Answer: b

Explanation: A session is started with the function session_start() . The session variables are set with the
PHP global variable which is $_SESSION.

11.Session variables are set with the PHP global variable: $_SESSION.

12.The session_start() function must be the very first thing in your document. Before any HTML tags.

13.When you want to store user data in a session use the . . . . array.

A) $_SESSION

B) SYS_SESSION

C) $SESSION

D) $_SESSIONS

Answer:-A

14.

Sessions allow you to

A) store persistent user preference on a site

B) save user authentication information from page to page

C) create multipage forms

D) all of above

Answer:-D

15.
A snapshot of the session data can be taken at any time and written out to a file.

A) True

B) False

Answer:-A

16.

When the session data is written to a file, it can be read back, decoded and applied to the current
session using the . . . . function.

A) session_reset()

B) session_get_cookie_params()

C) session_encode()

D) session_decode()

Answer:-D

17.

session_destroy() instantly destroy elements of the $_SESSION array.

A) True

B) False

Answer:-B

18.

Appending session data to an absolute URL does not represent a security risk.

A) True

B) False

Answer:-B
19.

If the php.ini register_globals directive is set, session data becomes available in the . . . . namespace.

A) Global

B) Local

Answer:-A

20.
No expiry date is set in the cookie that PHP sets for the session. The session remains current only as long
as the browser is active. When the browser is restarted the cookie is not stored. This behavior can be
changed by altering . . . . . setting in php.ini file.

A) cookie_lifetime

B) session.cookie_life_time

C) session.cookie_lifetime

D) cookie_life_time

Answer:-C

21.

session_destroy() erases all session variable.

A) True

B) False

Answer:-A

22.When a session ia active, PHP provides a special constant called

a.SID
b.CID

c.DID

d.None of them

Answer: (a).SID

23.If you want PHP to transparently handle passing session variables for you when cookies are not
available, you have to configure

a.enable-trans-sid option

b.enable-track-vars option

c.disable-tans-vars option

d.Both a and b

Answer: (d).Both a and b

24.A special kind of a file that is located in filesystem of your browser and can be read and write from
web server, is calls as

a.Session

b.Cookies

c.Script

d.All of them

Answer: (c).Script

25.Using $_SESSION, $HTTP_SESSION_VARS functions can be dangerous, so that you can use

a.session_destroy ( )

b.session_unset ( )

c.set ( )

d.None of them
Answer: (b).session_unset ( )

26.In PHP, cookies are set by using the

a.setcookie ( ) function

b.set ( ) function

c.cookie_set ( ) function

d.None of them

Answer: (a).setcookie ( ) function

27.www-authenticate mechanism works only under the

a.Apache web server

b.CGI servers

c.ISS servers

d.PWS servers

Answer: (a).Apache web server

28.What kind of session will maintain its identity as long as user stays within a site?

a.Cookie based session

b.Variable based session

c.Session

d.None of them

Answer: (b).Variable based session


29.A period of time during which a particular person, views a number of web pages at a particular
machine is called as

a.Session

b.Cookies

c.Parsing

d.None of them

Answer: (a).Session

30.A function that takes no argument s and return a string, which is unique key corresponding to a
particular session

a.session_name ( )

b.session_params ( )

c.session_id ( )

d.id ( )

Answer: (c).session_id ( )

31.Name, value, expire, patrh, httponly, domain, secure all of these are arguments of

a.session ( ) function

b.setcookie ( ) function

c.reset_cookie ( ) function

d.None of them

Answer: (b).setcookie ( ) function

32.To initiate a session which function is used?

a.start ( )

b.s_start ( )
c.session_start ( )

d.session_str ( )

Answer: (c).session_start ( )

33.If you want to free all variables in a session, which function you can usea.session_destroy (
)b.session_unset ( )c.set ( )d.All of them

Answer: (b).session_unset ( )

34.Which PHP function offers to send raw arbitrary HTTP headers?

a.setcookie ( )

b.set_header ( )

c.header ( )

d.All of them

Answer: (b).set_header ( )

35.PHP is not configured to transparently pass session IDs in the

a.GET argument

b.POST argument

c.HEADER arguments

d.Both a and b

Answer: (d).Both a and b

36.$_SESSION array is one of superglobal variables introduced in

a.PHP2.1

b.PHP3
c.PHP4.1

d.PHP6

Answer: (c).PHP4.1

37.When value of sessionauto_start ( ) function is zero it means that

a.Session is started

b.No session data will be available

c.Session is terminated

d.None of them

Answer: (b).No session data will be available

38.Session_unset ( ) takes

a.1 argument

b.2 arguments

c.3 arguments

d.No argument

Answer: (d).No argument

39.HTTP protocols by which browsers talk to a web server isa.Valuelessb.Statelessc.Uselessd.None of


them

Answer: (b).Stateless

40.Meaning of superglobal arrays is it can be

a.Referenced inside a function

b.Referenced outside of function


c.Used without declaring global first

d.All of them

Answer: (d).All of them

41.Secure ( ) argument in setcookie function returns result

a.In integer form

b.In string form

c.In boolean form

d.None of them

Answer: (c).In boolean form

42.sessions, cookies name/value pair are added to the

a.Superglobal array

b.$_COOKIE

c.Global function

d.Both a and b

Answer: (d).Both a and b

43.Php.ini file can be viewable by calling

a.info ( ) function

b.ini_file ( ) function

c.phpinfo ( ) function

d.php_ini ( ) function

Answer: (c).phpinfo ( ) function

44.Which two predefined variables are used to retrieve information from forms?
a.$GET & $SET

b.$_GET & $_SET

c.$_GET & $_SET

d.GET & SET_SET

45.The attack which involves the insertion of malicious code into a page frequented by other users is
known as..

a.basic sql injection

b.advanced sql injection

c.cross-site scripting

d.scriptingen

46.When you use the $_POST variable to collect data, the data is visible to..

a.none

b.only you

c.everyone

d.selected few

Answer: (b).only you

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

a.$BOTH

b.$_BOTH

c.$REQUEST

d.$_REQUEST

Answer: (d).$_REQUEST
48.Which one of the following should not be used while sending passwords or other sensitive
information?a.GET

b.POST

c.REQUEST

d.NEXT

Answer: (a).GET

49.Which function is used to remove all HTML tags from a string passed to a form?a.remove_tags()

b.strip_tags()

c.tags_strip()

d.tags_remove()

Answer: (b).strip_tags()

50.What will be the value of the variable $input in the following PHP code?<?php $input =
"Swapna<td>Lawrence</td>you are really<i>pretty</i>!"; $input = strip_tags($input,"<i></i>"); ?>

a.Swapna Lawrence you are really pretty!b.Swapna <td>Lawrence</td> you are really<i>pretty</i>!

c.Swapna <td>Lawrence</td> you are really pretty!

d.Swapna Lawrence you are really<i>pretty</i>!

Answer: (d).Swapna Lawrence you are really<i>pretty</i>!

51.To validate an email address, which flag is to be passed to the function


filter_var()?a.FILTER_VALIDATE_EMAIL

b.FILTER_VALIDATE_MAIL

c.VALIDATE_EMAIL

d.VALIDATE_MAIL

Answer: (a).FILTER_VALIDATE_EMAIL
52.How many validation filters like FILTER_VALIDATE_EMAIL are currently available?

a.5

b.6

c.7

d.8

Answer: (c).7

53.How many predefined variables does PHP use to authenticate a user?

a.1

b.2

c.3

d.4

Answer: (b).2

54.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.i) and ii)

b.ii) and iv)

c.i) and iv)

d.ii) and iii)

Answer: (c).i) and iv)


55.Which of the following PHP function is commonly used when handling authentication via PHP?

i) header()

ii) footer()

iii) inset()

iv) isset()

a.i) and iv)

b.ii) and iv)

c.ii) and iii)

d.i) and iii)

Answer: (a).i) and iv)

56.Which function is used to verify whether a variable contains a value?a.header()

b.footer()

c.inset()

d.isset()

Answer: (d).isset()

57.Which of the following are types of PHP authentication implementation methodologies?

i) Hard-coding a login pair directly into the script

ii) File-based authentication

iii) Data-based authentication

iv) PEAR’S HTTP authentication

a.ii) and iii)

b.i) and iv)

c.ii), iii) and iv)

d.All of the mentioned


Answer: (d).All of the mentioned

58.In which authentication method does changing the username or password can be done only by
entering the code and making the manual adjustment.

a.Hard-coding a login pair directly into the script

b.File-based authentication

c.Data-based authentication

d.PEAR’S HTTP authentication

Answer: (a).Hard-coding a login pair directly into the script

59.The authenticationFile.txt, the file which stores username and password should be stored _ the
server document root.

a.Inside

b.Outside

c.Within

d.None of the mentioned

Answer: (b).Outside

60.Which function is used to split a string into a series of substrings, with each string boundary is
determined by a specific separator?a.break()

b.divide()

c.explode()

d.md5()

Answer: (c).explode()
Say I want to change the extension of a PHP file, which of the following statements should I edit to
change from .php to .html in the httpd.conf file?

a. AddType application/x-httpd-php .php

b. AddType application/x-httpd-php .asp

c. AddType application/x-httpd-asp .php

d. AddType application/x-httpd-asp .asp

Answer: (a).

AddType application/x-httpd-php .php

61.The developers of PHP deprecated the safe mode feature as of which PHP version.

a. PHP 5.1.0

b. PHP 5.2.0

c. PHP 5.3.0

d. PHP 5.3.1

Answer: (c).

PHP 5.3.0

62.The session_start() function must appear..

a. after the html tag

b. after the body tag

c. before the body tag

d. before the html tag

Answer: (d).

before the html tag

63.What is the return type of session_set_save_handler() function?

a. boolean
b. integer

c. float

d. character

Answer: (a).

boolean

64.Which one of the following statements should be used to disable just the fopen(), and file()
functions?

a. disable_functions = fopen(), file()

b. disable_functions = fopen, file

c. functions_disable = fopen(), file()

d. functions_disable = fopen, file

Answer: (b).

disable_functions = fopen, file

65.Which one of the following statements should be used to disable the use of two classes administrator
and janitor?

a. disable_classes = “administrator, janitor”

b. disable_classes = class administrator, class janitor

c. disable_classes = class “administrator”, class “janitor”

d. disable_class = class “administrator”, class “janitor”

Answer: (a).

66.disable_classes = “administrator, janitor”

67.What is the default value of max_execution_time directive? This directive specifies how many
seconds a script can execute before being terminated.

a. 10
b. 20

c. 30

d. 40

Answer: (c).

30

68.The memory_limit is only applicable if _ is enabled when you configure PHP. Fill in the blank.

a. –enable-limit

b. -enable-memory-limit

c. –enable-memory-limit

d. -memory-limit

Answer: (c).

–enable-memory-limit

69.Suppose all web material is located within the directory /home/www. To prevent users from viewing
and manipulating files such as /etc/password, which one of the following statements should you use?

a. open_dir = “/home/www/”

b. open_dir = /home/www/

c. open_basedir = /home/www/

d. open_basedir = “/home/www/”

Answer: (d).

open_basedir = “/home/www/”

70.Which Apache directive outputs Apache’s server version, server name, port and compile-in modules?

a. ServerSignature

b. ServerName
c. ServerDetails

d. ServerInfo

Answer: (a).

ServerSignature

71.Which directive determines which degree of server details is provided if the ServerSignature directive
is enabled?

a. ServerAddons

b. ServerExtra

c. ServerTokens

d. ServerDetails

Answer: (c).

ServerTokens

72.Which directive should we disable to obscure the fact that PHP is being used on our server?

a. show_php

b. expose_php

c. print_php

d. info_php

Answer: (b).

expose_php

73.What is the default time(in seconds) for which session data is considered valid?

a. 1800

b. 3600

c. 1440

d. 1540
Answer: (c).

1440

74.Which one of the following function is used to start a session?

a. start_session()

b. session_start()

c. session_begin()

d. begin_session()

Answer: (b).

session_start()

75.Which function is used to erase all session variables stored in the current session?

a. session_destroy()

b. session_change()

c. session_remove()

d. session_unset()

Answer: (d).

session_unset()

76.What will the function session_id() return is no parameter is passed?

a. Current Session Identification Number

b. Previous Session Identification Number

c. Last Session Identification Number

d. Error

Answer: (a).
Current Session Identification Number

77.Which one of the following statements should you use to set the session username to Nachi?

a. $SESSION[‘username’] = “Nachi”;

b. $_SESSION[‘username’] = “Nachi”;

c. session_start(“nachi”);

d. $SESSION_START[“username”] = “Nachi”;

Answer: (b).

$_SESSION[‘username’] = “Nachi”;

78.What will be the output of the following PHP code? Say your previous session username was nachi.

unset($_SESSION['username']);

printf("Username now set to: %s", $_SESSION['username']);

a. Username now set to: nachi

b. Username now set to: System

c. Username now set to:

d. Error

Answer: (c).

Username now set to:

78.An attacker somehow obtains an unsuspecting user’s SID and then using it to impersonate the user in
order to gain potentially sensitive information. This attack is known as..

a. session-fixation

b. session-fixing

c. session-hijack

d. session-copy
Answer: (a).

session-fixation

79.Which parameter determines whether the old session file will also be deleted when the session ID is
regenerated?

a. delete_old_file

b. delete_old_session

c. delete_old_session_file

d. delete_session_file

Answer: (b).

delete_old_session

80.Which function effectively deletes all sessions that have expired?

a. session_delete()

b. session_destroy()

c. session_garbage_collect()

d. session_expired_delete()

Answer: (c).

session_garbage_collect()

81.Which function is used to transform PHP’s session-handler behavior into that defined by your custom
handler?

a. session_set_save()

b. session_set_save_handler()

c. Session_handler()

d. session_save_handler()
Answer: (b).

session_set_save_handler()
PHP MCQ QUESTIONS

MODULE-2

FUNCTIONS

1. How many types of functions are available in php?

A. 5
B. 4

C. 3
D. 2
Ans : D
Explanation: PHP provides us with two major types of functions Built-in functions and User
Defined Functions.
2. Which of the following is not a built-in function in php ?
A. print_r()
B. fopen()
C. fclosed()
D. gettype()
Ans : C

Explanation: fclosed() is not a built-in function in php.

3. Why should we use functions?

A. Reusability
B. Easier error detection
C. Easily maintained
D. All of the above
Ans : D
Explanation: we use functions because they provide Reusability, Easier error detection, Easily
maintained.

4. A function name always begins with the keyword _________.

A. fun
B. def
C. function

D. None of the above


Ans : C
Explanation: A function name always begins with the keyword function.

5. A function name cannot start with a ____

A. alphabet
B. underscore
C. number
D. Both C and B
Ans : C
Explanation: A function name cannot start with a number. It can start with an alphabet or
underscore.

6. A function name is not case-sensitive?

A. True
B. False
C. Only user-defined function is case-sensitive
D. None of the above
Ans : A
Explanation: A function name is not case-sensitive, the following statement is true.
7. A function name is not case-sensitive?

<?php

function funclfc()
{
echo "This is letsfindcourse";
}

// Calling the function


funclfc();

?>

A. This is lfc
B. This is letsfindcourse
C. No Output
D. Error
Ans : B
Explanation: The output of the following PHP code This is letsfindcourse

8. A function name is not case-sensitive?

<?php

function prolfc($num1, $num2, $num3)


{
$mul = $num1 * $num2 * $num3;
echo "The product is $mul";
}

prolfc(1, 2, 3, 4);

?>
A. 24
B. 8
C. 6
D. Error: too many arguments.
Ans : C
Explanation: The output of the following PHP code is 6.

9. A function in PHP which starts with double underscore is known as __________.

A. Magic Function
B. Inbuilt Function
C. Default Function
D. User Defined Function
Ans : A
Explanation: PHP functions that start with a double underscore - a "__" are called magic
functions in PHP.

10. PHP has over ____________ built-in functions that can be called directly.

A. 10
B. 100
C. 1000
D. 10000
Ans : C

Explanation: PHP has over 1000 built-in functions that can be called directly

11. Function names are case-sensitive.

A. True
B. False
C. Only Built-In function
D. Only User-defined function
Ans : B

Explanation: Function names are NOT case-sensitive.

12. What will be the output of the following code?

<?php declare(strict_types=1); // strict requirement

function addNumbers(int $a, int $b) {

return $a + $b;

echo addNumbers(5, "5 days");

?>

A. 5+5days
B. 55days
C. No Output
D. Error

Ans : D

Explanation: since strict is enabled and "5 days" is not an integer, an error will be thrown.

13. What will be the output of the following code?

<?php declare(strict_types=1); // strict requirement ?>

<?php

function setHeight(int $minheight = 50) {

echo "The height is : $minheight <br>";

}
setHeight(350);

?>

A. The height is : 350


B. The height is : 50
C. No Output
D. Error

Ans : A

Explanation: The height is: 350 be the output of the following code.

14. In which of the following cases would function empty() return FALSE?

A. $x; echo empty($x);


B. $x=FALSE; echo empty($x);
C. $x=TRUE; echo empty($x);
D. $x=NULL; echo empty($x);

Ans : C

Explanation: $x=TRUE; echo empty($x); of the following cases would function empty()
return FALSE.

15. What will be the output of the following code?

<?php

function WRITEMSG() {

echo "Hello world!";

writemsg();
?>

A. Hello world!
B. Null
C. No Output
D. None of the above

Ans : A

Explanation: Hello world! be the output of the following code because Function names are
NOT case-sensitive.
16. Which type of function call is used in line 8 in the following PHP code?

1. ​<?php
2. ​function​ calc​(​$price​,​ ​$tax​)
3. {​
4. ​$total​ ​=​ ​$price​ ​+​ ​$tax​;
5. }​
6. ​$pricetag​ ​=​ ​15​;
7. ​$taxtag​ ​=​ ​3​;
8. calc​(​$pricetag​,​ ​$taxtag​)​;
9. ​?>

a) Call By Value

b) Call By Reference

c) Default Argument Value

d) Type Hinting

Answer: a

Explanation: If we call a function by value, we actually pass the values of the arguments which
are stored or copied into the formal parameters of the function. Hence, the original values are
unchanged only the parameters inside the function changes.

17​. Which function is used to get ASCII value of a character in PHP ?


● asc()
● chr( )
● ascii()
● val( )
Answer​: chr( ) function is used to get ASCII value of a character in PHP.

18​. ______ is used to unset a variable in PHP ?


● delete()
● unset()
● unlink()
● delete();
​Answer: unset() is used to unset a variable in PHP

19. Which of the following PHP functions accepts any number of parameters?
● func_get_args()
● func_get_argv()
● get_argv()
● get_argc()

Answer: func_get_args()

20. what are the differences between include() and require()?


I.​ require generates a fatal error and stops the script

II.​ include produces a warning and continues the script

III.​ require produces warning and continues the script

IV.​ include generates a fatal error and stops the script

a.​Both (I) and (II) correct

B​ Both (II) and (III) correct

C​ Both (I) and (III) correct

D.none of these above

Answer: A

21. Which function is used to determine whether a variable is set or not?


A​ unset()
B​ isset()

C​ set()

D​ none of these above

Answer: B

22.Which function is used to determine whether a variable is empty or not?


A​ check()

B​ empty()

C​ determine()

D.none of these above

Answer: B

21. Which one of the following is the right way of defining a function in PHP?

A. function { function body }


B.data type functionName(parameters) { function body }
C. functionName(parameters) { function body }
D.function fumctionName(parameters) { function body }

Answer:​ Option D

22.​ Which one of the following PHP functions can be used to build a function that accepts
any number of arguments?

● A. func_get_argv()
● B. func_get_argc()
● C. get_argv()
● D. get_argc()

Answer: Option B

23.​ Which one of the following PHP functions can be used to find files?

● A. glob()
● B. file()

● C. fold()

● D. get_file()

Answer: Option A

23.The filesize() function returns the file size in ___.

● A. bits

● B. bytes

● C. kilobytes

● D. gigabytes

Answer: Option B

24.Which one of the following PHP functions is used to determine a file’s last access time?

● A. fileltime()

● B. filectime()

● C. fileatime()

● D. filetime()

Answer: Option C

25.Which one of the following function is capable of reading a file into an array?

● A. file()
● B. arrfile()

● C. arr_file()

● D. file_arr()

Answer: Option A

26.​ What will be the output of the following PHP code?

< ?php

function a()

function b()

echo ​'I am b'​;

echo ​'I am a'​;

a();

a();
?>

● A. I am b

● B. I am bI am a

● C. Error

● D. I am a Error

Answer: Option D

Explanation:

This will be the output- I am a Fatal error: Cannot redeclare b()

27.​ What will be the output of the following PHP code?

< ?php

function a()

function b()

echo ​'I am b'​;

echo ​'I am a'​;

b();

a();

?>
● A. I am b

● B. I am bI am a

● C. Error.

● D. I am a Error

Answer: Option C

Explanation:

This will be the output- Fatal error: Call to undefined function b(). You cannot call a
function which is inside a function without calling the outside function.

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

< ?php

$op2 = "blabla";

function foo($op1)

echo ​$op1​;

echo ​$op2​;

foo("hello");

?>

● A. helloblabla

● B. Error
● C. hello

● D. helloblablablabla

● View Answer

● Workspace

● Report

● Discuss

Answer & Explanation

Answer: Option C

Explanation:

If you want to put some variables in a function that was not passed by it, you must use
“global”. Inside the function type global $op2.

29. A function in PHP which starts with __ (double underscore) is known as..

● A. Magic Function

● B. Inbuilt Function

● C. Default Function

● D. User Defined Function

● View Answer

● Workspace

● Report
● Discuss

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

< ?php

function foo($msg)

echo ​"$msg"​;

$var1 = "foo";

$var1("will this work");

?>

● A. Error.

● B. $msg

● C. 0

● D. will this work

Answer: Option D

Explanation:

It is possible to call a function using a variable which stores the function name.

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

< ?php
$str = "Hello World"

echo ​wordwrap($str,5,"

\n")​;

?>

● A. Hello World

● B. Hello
World

● C. Hell
o wo
rld

● D. World

Answer: Option B

Explanation:

The wordwrap() function wraps a string into new lines when it reaches a specific length.

32.Which function is useful when you want to output the executed command’s result?

● A. out_cmm()

● B. out_system()

● C. cmm()

● D. system()
● View Answer

● Workspace

● Report

● Discuss

Answer: d

33. Which of the following function returns a text in title case from a variable?

A.​ucwords($var)

B.​upper($var)

C.​toupper($var)

D.​ucword($var)

Answer : ​Option ​A

34. The var_dump() function displays

● the binary value of a variable


● any PHP value in a human readable form
● the whether a variable is empty or not
● none of these above

Answer: any PHP value in a human readable form

35. PHP function arguments are modified in function definition and

● In a function call
● In execution time
● In deceleration time
● None of them

Answer: In a function call

36. How many ways that PHP offers to modify arguments of a function?

● 1
● 2
● 3
● 4

Answer: 2

37. Which of the following statements is more suitable if you want to output a blend of
static text and dynamic information stored within one or several variables?

A. echo ( )

B. print ( )

C. Print f ( )

D. None of above

Answer: c

38.Variables/functions in PHP don't work directly with:

a. echo()

b. isset()
c. print()

d. All of the above

Ans: b

39) The inbuilt function to get the number of parameters passed is:

a. arg_num()

b. func_args_count()

c. func_num_args()

d. None of the above

Ans: c

40. Which statement is correct about passing by value parameters?

● It cannot change the actual parameter value

● It can change the actual parameter value

● Parameter is always in read-write mode

● None of them

Answer: A

41.actual parameters must be variables, is a condition of


● When parameters are passed by value

● When parameters are passed outside the function

● When parameters are passed by reference

● When parameters are passed outside the class

Answer: c

42. int&x is used when

● X is passed by value

● X is passed by reference

● X is declared outside of the function

● None of them

Answer: B
PHP( FUNCTIONS)MCQ QUIESTIONS
1. PHP’s numerically indexed array begins with position __.

A. 1
B. 2
C. 0
D. -1

View Answer

Answer: C

Like many programming languages, the first element of an array has an index value of 0.

2. Which of the functions is used to sort an array in descending order?

A. sort()
B. asort()
C. rsort()
D. dsort()

View Answer

Answer: C

sort() function is used to sort in ascending order where as rsort() meaning reverse sort is
used for sorting in descending order.

4.Which of the following are correct ways of creating an array?


(i) state[0] = "karnataka";
(ii) $state[] = array("karnataka");
(iii) $state[0] = "karnataka";
(iv) $state = array("karnataka");

A. (iii) and (iv)


B. (ii) and (iii)
C. Only (i)
D. (ii), (iii) and (iv)
Answer: A

A variable name should start with $ symbol which is not present in i) and you need not put
the square brackets when you use the array() constructor.

4. What will be the output of the following php code?

< ?php
$states = array("karnataka" => array
( "population" => "11,35,000", "captial" => "Bangalore"),
"Tamil Nadu" => array( "population" => "17,90,000",
"captial" => "Chennai") );
echo $states["karnataka"]["population"];
?>

A. karnataka 11,35,000
B. 11,35,000
C. population 11,35,000
D. karnataka population

Answer :B

5. Which function can be used to move the pointer to the previous array
position?

A. last()
B. before()
C. prev()
D. previous()

Answer : C

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


< ?php
$fruits = array ("apple", "orange", "banana");
echo (next($fruits));
echo (next($fruits));
?>

A. orangebanana
B. appleorange
C. orangeorange
D. appleapple

Answer : A

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


< ?php
$state = array ("Karnataka", "Goa", "Tamil Nadu",
"Andhra Pradesh");
echo (array_search ("Tamil Nadu", $state) );
?>

A. True
B. 1
C. False
D. 2

Answer : D

8. Which in-built function will add a value to the end of an array?

A. array_unshift()
B. into_array()
C. inend_array()
D. array_push()

Answer : D

9.Which function will return true if a variable is an array or false if it is not?

A. this_array()
B. is_array()
C. do_array()
D. in_array()

Answer :B

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


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

A. 3
B. 4
C. 5
D. 6

Answer : D

11.Which function returns an array consisting of associative key/value pairs?

A. count()
B. array_count()
C. array_count_values()
D. count_values()

Answer :C

12.Say in the above question you need to get the array sorted in the manner we
humans would have done it i.e picture1 then picture2 etc.. Which of the following
function should be used?

A. dsort()
B. casesort()
C. natcasesort()
D. naturalsort()

Answer : C

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


< ?php
$fruits = array ("apple", "mango", "peach", "pear",
"orange");
$subset = array_slice ($fruits, 2);
print_r ($subset);
?>

A. Array ( [0] => peach )


B. Array ( [0] => apple [1] => mango [2] => peach )
C. Array ( [0] => apple [1] => mango )
D. Array ( [0] => peach [1] => pear [2] => orange )

Answer : D

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


< ?php
$fruits = array ("apple", "mango", "peach", "pear",
"orange");
$subset = array_splice ($fruits, 2);
print_r ($fruits);
?>

A. Error
B. Array ( [0] => apple [1] => mango [2] => peach )
C. Array ( [0] => apple [1] => mango )
D. Array ( [0] => pear [1] => orange )

Answer : C

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


< ?php
$number = array ("4", "hello", 2);
echo (array_sum ($number));
?>

A. 4hello2
B. 4
C. 2
D. 6

ANSWER : D

15. Which one of the following PHP functions can be used to build a function that
accepts any number of arguments?

A. func_get_argv()
B. func_get_argc()
C. get_argv()
D. get_argc()

Answer: B

16.Which one of the following PHP functions can be used to find files?

A. glob()
B. file()
C. fold()
D. get_file()

Answer A

17. The filesize() function returns the file size in ___.

A. bits
B. bytes
C. kilobytes
D. gigabytes

Answer : B
18. Which one of the following PHP function is used to determine a file’s last
access time?

A. fileltime()
B. filectime()
C. fileatime()
D. filetime()

Answer : C
19.Which one of the following function is capable of reading a file into a string
variable?

A. file_contents()
B. file_get_contents()
C. file_content()
D. file_get_content()

Answer : B

20. Which one of the following function is capable of reading a specific number of
characters form a file?

A. fgets()
B. fget()
C. fileget()
D. filegets()

Answer : A

21. Which one of the following function outputs the contents of a string variable
to the specified resource?

A. filewrite()
B. fwrite()
C. filewrites()
D. fwrites()

Answer : B

22. Which function sets the file filename’s last-modified and last-accessed
times?

A. sets()
B. set()
C. touch()
D. touched()

Answer : C

23. Which function is useful when you want to output the executed command’s
result?

A. out_cmm()
B. out_system()
C. cmm()
D. system()

Answer : D
24. Which one of the following function reads a directory into an Array?

A. scandir()
B. readdir()
C. scandirectory()
D. readdirectory()

Answer : A

25. Which one of the following is the right way of defining a function in PHP?

A. function { function body }


B. data type functionName(parameters) { function body }
C. functionName(parameters) { function body }
D. function fumctionName(parameters) { function body }

Answer : D

26. Type Hinting was introduced in which version of PHP?

A. PHP 4
B. PHP 5
C. PHP 5.3
D. PHP 6

Answer : B
27. Which of the following PHP functions can be used to get the current memory
usage?

A. get_usage()
B. get_peak_usage()
C. get_memory_usage()
D. get_memory_peak_usage()

Answer : C

28.Which of the following PHP functions can be used for generating unique id’s?

A. uniqueid()
B. id()
C. md5()
D. mdid()

Answer : A

29.Which one of the following functions can be used to compress a string?

A. zip_compress()
B. zip()
C. compress()
D. gzcompress()

Answer : D

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


< ?php
echo "chr(52)";
?>

A. 1
B. 2
C. 3
D. 4

Answer : D
31. What will be the output of the following PHP code?
< ?php
echo ord ("hi");
?>

A. 106
B. 103
C. 104
D. 209

Answer : C

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


< ?php
$str = "Hello World"
echo wordwrap($str,5,"
\n");
?>

A. Hello World
B. Hello
World
C. Hello world
D. World

Answer : B

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


< ?php
echo ucwords("i love my country");
?>
A. I love my country
B. i love my Country
C. I love my Country
D. I Love My Country
Answer D

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


< ?php
echo lcfirst("welcome to India");
?>

A. welcome to India
B. welcome to india
C. Welcome to India
D. Welcome to india

Answer : A

35. What will happen in this function call?


< ?php
function calc($price,$tax)
{
$total = $price + $tax;
}
$pricetag = 15;
$taxtag = 3;
calc($pricetag, $taxtag);
?>

A. Call By Value
B. Call By Reference
C. Default Argument Value
D. Type Hinting
Answer : A

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


< ?php
function calc($price, $tax="")
{
$total = $price + ($price * $tax);
echo "$total";
}
calc(42);
?>

A. Error
B. 0
C. 42
D. 84

Answer : C

35. Which of the following are valid function names?


i) function()
ii) €()
iii) .function()
iv) $function()
A. Only (ii)
B. None of the mentioned.
C. All of the mentioned.
D. (iii) and (iv)

Answer : A
36. What will be the output of the following PHP code?
< ?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
a();
a();
?>

A. I am b
B. I am bI am a
C. Error
D. I am a Error

Answer D

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


< ?php
$op2 = "blabla";
function foo($op1)
{
echo $op1;
echo $op2;
}
foo("hello");
?>
A. helloblabla
B. Error
C. hello
D. helloblablablabla

Answer C

37. A function in PHP which starts with __ (double underscore) is know as.

A. Magic Function
B. Inbuilt Function
C. Default Function
D. User Defined Function

Answer A

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


< ?php
function foo($msg)
{
echo "$msg";
}
$var1 = "foo";
$var1("will this work");
?>

A. Error
B. $msg
C. 0
D. will this work

Answer D
1. PHP’s numerically indexed array begin with position __.

 A. 1
 B. 2
 C. 0
 D. -1

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option C

Explanation:

Like many programming languages, the first element of an array has an index value of 0.

2. Which of the functions is used to sort an array in descending order?

 A. sort()
 B. asort()
 C. rsort()
 D. dsort()

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option C

Explanation:

sort() function is used to sort in ascending order where as rsort() meaning reverse sort is used for
sorting in descending order.

3. Which of the following are correct ways of creating an array?


(i) state[0] = “karnataka”;
(ii) $state[] = array(“karnataka”);
(iii) $state[0] = “karnataka”;
(iv) $state = array(“karnataka”);
 A. (iii) and (iv)
 B. (ii) and (iii)
 C. Only (i)
 D. (ii), (iii) and (iv)

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option A

Explanation:

A variable name should start with $ symbol which is not present in i) and you need not put the
square brackets when you use the array() constructor.

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


< ?php
$fruits = array ("mango", "apple", "pear", "peach");
$fruits = array_flip($fruits);
echo ($fruits[0]);
?>

 A. mango
 B. Error
 C. peach
 D. 0

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option B

Explanation: As we are flipping the values, $fruits["mango"] = 0, $fruits["apple"] = 1 and so on.

5. What will be the output of the following php code?


< ?php
$states = array("karnataka" => array
( "population" => "11,35,000", "captial" => "Bangalore"),
"Tamil Nadu" => array( "population" => "17,90,000",
"captial" => "Chennai") );
echo $states["karnataka"]["population"];
?>

 A. karnataka 11,35,000
 B. 11,35,000
 C. population 11,35,000
 D. karnataka population

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option B

Explanation:

Treat states as a multidimensional array and accordingly traverse it to get the value.

6. Which function will return true if a variable is an array or false if it is not?

 A. this_array()
 B. is_array()
 C. do_array()
 D. in_array()

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option B

Explanation:

A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean
is_array(mixed variable).

7. Which in-built function will add a value to the end of an array?

 A. array_unshift()
 B. into_array()
 C. inend_array()
 D. array_push()

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option D

Explanation:

array_push adds a value to the end of an array, returning the total count of elementsin the array
after the new value has been added.

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


< ?php
$state = array ("Karnataka", "Goa", "Tamil Nadu",
"Andhra Pradesh");
echo (array_search ("Tamil Nadu", $state) );
?>

 A. True
 B. 1
 C. False
 D. 2

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option D

Explanation:

The array_search() function searches an array for a specified value, returning its key if located
and FALSE otherwise.

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


< ?php
$fruits = array ("apple", "orange", "banana");
echo (next($fruits));
echo (next($fruits));
?>

 A. orangebanana
 B. appleorange
 C. orangeorange
 D. appleapple

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option A

Explanation:

The next() function returns the array value residing at the position immediately following that of
the current array pointer.

10. Which function can be used to move the pointer to the previous array position?

 A. last()
 B. before()
 C. prev()
 D. previous()

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option C

Explanation:

prev()

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


< ?php
$fruits = array ("apple", "orange", array ("pear", "mango"),
"banana");
echo (count($fruits, 1));
?>
 A. 3
 B. 4
 C. 5
 D. 6

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option D

Explanation:

The array entity holding pear and mango is counted as an item, just as its contents are.

12. Which function returns an array consisting of associative key/value pairs?

 A. count()
 B. array_count()
 C. array_count_values()
 D. count_values()

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option C

Explanation:

array_count_values()

13. Say in the above question you need to get the array sorted in the manner we humans would
have done it i.e picture1 then picture2 etc.. Which of the following function should be used?

 A. dsort()
 B. casesort()
 C. natcasesort()
 D. naturalsort()
 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option C

Explanation:

natcasesort()

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


< ?php
$fruits = array ("apple", "mango", "peach", "pear",
"orange");
$subset = array_slice ($fruits, 2);
print_r ($subset);
?>

 A. Array ( [0] => peach )


 B. Array ( [0] => apple [1] => mango [2] => peach )
 C. Array ( [0] => apple [1] => mango )
 D. Array ( [0] => peach [1] => pear [2] => orange )

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option D

Explanation:

The array_slice() function returns a section of an array based on a starting and ending offset
value.

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


< ?php
$fruits = array ("apple", "mango", "peach", "pear",
"orange");
$subset = array_splice ($fruits, 2);
print_r ($fruits);
?>
 A. Error
 B. Array ( [0] => apple [1] => mango [2] => peach )
 C. Array ( [0] => apple [1] => mango )
 D. Array ( [0] => pear [1] => orange )

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option C

Explanation:

The array_splice() function removes all elements of an array found within a specified range.

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


< ?php
$number = array ("4", "hello", 2);
echo (array_sum ($number));
?>

 A. 4hello2
 B. 4
 C. 2
 D. 6

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option D

Explanation:

The array_sum() function add all the values of the input array together, returning the final sum. If
a string datatype is found, it’ll be ignored.

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

1. <?php
2. $state = array ("Karnataka", "Goa", "Tamil Nadu",
3. "Andhra Pradesh");
4. echo (array_search ("Tamil Nadu", $state) );
5. ?>

a) True
b) 1
c) False
d) 2
View Answer

Answer: d
Explanation: The array_search() function searches an array for a specified value, returning its
key if located and FALSE otherwise.

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

1. <?php
2. $fruits = array ("apple", "orange", "banana");
3. echo (next($fruits));
4. echo (next($fruits));
5. ?>

a) orangebanana
b) appleorange
c) orangeorange
d) appleapple
View Answer

Answer: a
Explanation: The next() function returns the value of the next element in the array. In the first
‘next($fruits)’ call, it will print orange which is next to apple and so on.

19. Which of the following function is used to get the value of the previous element in an array?
a) last()
b) before()
c) prev()
d) previous()
View Answer

Answer: c
Explanation: The prev() function returns the previous element in the array.

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

1. <?php
2. $fruits = array ("apple", "orange", array ("pear", "mango"),
3. "banana");
4. echo (count($fruits, 1));
5. ?>
a) 3
b) 4
c) 5
d) 6
View Answer

Answer: d
Explanation: The function count() will return the number of elements in an array. The parameter
1 counts the array recursively i.e it will count all the elements of multidimensional arrays.

21. Which function returns an array consisting of associative key/value pairs?


a) count()
b) array_count()
c) array_count_values()
d) count_values()
View Answer

Answer: c
Explanation: The function array_count_values() will count all the values of an array. It will
return an associative array, where the keys will be the original array’s values, and the values are
the number of occurrences

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

1. <?php
2. $cars = array("Volvo", "BMW", "Toyota");
3. echo "I like " . $cars[2] . ", " . $cars[1] . " and " . $cars[0] . ".";
4. ?>

a) I like Volvo, Toyota and BMW


b) I like Volvo, BMW and Toyota
c) I like BMW, Volvo and Toyota
d) I like Toyota, BMW and Volvo
View Answer

Answer: d
Explanation: The order of elements defined. In the echo statement when we call the elements of
array using its index, it will be printed accordingly. As index ‘0’ indicates ‘Volvo’, ‘1’ for
‘BMW’ and ‘2’ for Toyota’.

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

1. <?php
2. $fname = array("Peter", "Ben", "Joe");
3. $age = array("35", "37", "43");
4. $c = array_combine($age, $fname);
5. print_r($c);
6. ?>
a) Array (Peter Ben Joe)
b) Array ([Peter] => 35 [Ben] => 37 [Joe] => 43)
c) Array (35 37 43)
d) Array ([35] => Peter [37] => Ben [43] => Joe)
View Answer

Answer: d
Explanation: Here “keys” array is $age and “values” array is $fname. The function
array_combine() will create an array by using the elements from one “keys” array and one
“values” array. So when variable c is called, it will print keys and values.

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

1. <?php
2. $a=array("A","Cat","Dog","A","Dog");
3. $b=array("A","A","Cat","A","Tiger");
4. $c=array_combine($a,$b);
5. print_r(array_count_values($c));
6. ?>

a) Array ( [A] => 5 [Cat] => 2 [Dog] => 2 [Tiger] => 1 )


b) Array ( [A] => 2 [Cat] => 2 [Dog] => 1 [Tiger] => 1 )
c) Array ( [A] => 6 [Cat] => 1 [Dog] => 2 [Tiger] => 1 )
d) Array ( [A] => 2 [Tiger] => 1 )
View Answer

Answer: d
Explanation: The function The array_count_values() counts all the values of an array and the The
function array_combine() will create an array by using the elements from one “keys” array and
one “values” array.

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

1. <?php
2. $a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" =>
"yellow");
3. $a2 = array("e" => "red", "f" => "green", "g" => "blue", "h" =>
"orange");
4. $a3 = array("i" => "orange");
5. $a4 = array_merge($a2, $a3);
6. $result = array_diff($a1, $a4);
7. print_r($result);
8. ?>

a) Array ( [d] => yellow )


b) Array ( [i] => orange )
c) Array ( [h] => orange )
d) Array ( [d] => yellow [h] => orange )
View Answer
Answer: a
Explanation: The array_diff() function compares the values of two (or more) arrays, and returns
the differences. This function compares the values of two (or more) arrays, and return an array
that contains the entries from array1 that are not present in other arrays (array2, array3, etc).

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

1. <?php
2. $a1 = array("red", "green");
3. $a2 = array("blue", "yellow");
4. $a3 = array_merge($a1, $a2);
5. $a4 = array("a", "b", "c", "d");
6. $a = array_combine($a4, $a3);
7. print_r($a);
8. ?>

a) Array ( [a] => blue [b] => yellow [c] => red [d] => green )
b) Array ( [0] => blue [1] => yellow [2] => red [3] => green )
c) Array ( [0] => red [1] => green [2] => blue [3] => yellow )
d) Array ( [a] => red [b] => green [c] => blue [d] => yellow )
View Answer

Answer: d
Explanation: The function array_merge() merges one or more arrays into one array. If in the
function array_merge(), two or more array elements have the same key, the last one overrides the
others. The function array_combine() will create an array by using the elements from one “keys”
array and one “values” array. The program is the basic combined application of array_combine()
and array_merge().

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

1. <?php
2. $a = array("a" => "india", "b" => "brazil", "c" => "china");
3. echo array_shift($a);
4. echo "<br>";
5. array_pop($a);
6. print_r($a);
7. ?>

a)

india
Array ( [b] => Brazil )

b)

india
Array ( [a] => brazil )

c)
china
Array ( [a] => india )

d)

china
Array ( [a] => brazil )
View Answer
Answer: a
Explanation: The function array_shift() removes the first element from an array, and it returns
the value of the removed element and the function array_pop() deletes the last element of an
array. So “a” => “India”, “c” => “China” will be deleted and “b” => “Brazil” will be printed.

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

1. <?php
2. $a1 = array_fill(1, 4, "hello");
3. $b1 = array_fill(5, 1, "php");
4. $a2 = array_merge($a1, $a2);
5. print_r($a2);
6. echo "<br>";
7. print_r($b1);
8. ?>

a)

Array ( [1] => hello [4] => hello [5] => php )
Array ( [5] => php )

b)

Array ( [1] => hello [2] => hello [3] => hello [4] => hello )
Array ( [5] => php )

c)

Array ( [1] => hello [2] => hello [3] => hello [4] => hello [5] => php )
Array ( [5] => php )

d)

Array ( [1] => hello [2] => hello [3] => hello [4] => hello )
Array ( [1] => php )
View Answer
Answer: c
Explanation: Usage of array_fill() and array_merge() functions.
29. What will be the output of the following PHP code?

1. <?php
2. $names = array("Sam", "Bob", "Jack");
3. echo $names[0] . "is the brother of " . $names[1] . " and " . $names[1]
. ".";
4. ?>

a) Sam is the brother of Bob and Jack


b) Samis the brother of Bob and Bob
c) Sam is the brother of Jack and Bob
d) Error
View Answer

Answer: b
Explanation: Simple definition of array and using it in a string. We have used $names[1] twice
and hence Bob appears twice.

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

1. <?php
2. $names = array("Sam", "Bob", "Jack");
3. echo $names[0]."is the brother of ".$names[1]." and
".$names[1].".".$brother;
4. ?>

a) Sam is the brother of Bob and Bob) $brother


b) Sam is the brother of Bob and Bob)
c) $brother
d) Error
View Answer

Answer: d
Explanation: $brother undeclared.

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

1. <?php
2. $place = array("NYC", "LA", "Paris");
3. array_pop($place);
4. $place1 = array("Paris");
5. $place = array_merge($place, $place1);
6. print_r($place);
7. ?>

a) Array ( [0] => LA [1] => Paris [2] => Paris )


b) Array ( [0] => NYC [1] => LA [2] => Paris)
c) Array ( [0] => NYC [1] => LA [2] => Paris [3] => Paris )
d) Array ( [0] => LA [1] => Paris )
View Answer

Answer: b
Explanation: array_merge() and array_pop() yields that result.

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

1. <?php
2. $age = array("Harry" => "21", "Ron" => "23","Malfoy" => "21");
3. array_pop($age);
4. print_r(array_change_key_case($age, CASE_UPPER));
5. ?>

a) Array ( [Harry] => 21 [Ron] => 23 [Malfoy] => 21 )


b) Array ( [HARRY] => 21 [RON] => 23 [MALFOY] => 21 )
c) Array ( [HARRY] => 21 [RON] => 23 )
d) Array ( [Harry] => 21 [Ron] => 23 )
View Answer

Answer: c
Explanation: The function array_pop() will delete the last element of an array. So Malfoy => 21
will be deleted and the function array_change_key_case() will change all keys in an array to
lowercase or uppercase.

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

1. <?php
2. $a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" =>
"yellow");
3. $result = array_flip($a1);
4. print_r($result);
5. ?>

a) Array ( [red] => red [green] => green [blue] => blue [yellow] => yellow )
b) Array ( [a] => a [b] => b [c] => c [d] => d )
c) Array ( [red] => a [green] => b [blue] => c [yellow] => d )
d) Array ( [a] => red [b] => green [c] => blue [d] => yellow )
View Answer

Answer: c
Explanation: The function array_flip() flips/exchanges all keys with their associated values in an
array. So, in the above program “a” will be flipped with “red”, “b” will be flipped with “green”
and so on.

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

1. <?php
2. $a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" =>
"yellow");
3. $a2 = array("e" => "red","f" => "green", "g" => "blue");
4. $result = array_intersect($a1, $a2);
5. print_r($result);
6. ?>

a) Array ( [a] => red [b] => green [c] => blue )
b) Array ( [a] => red [b] => green [c] => blue [d] => yellow )
c) Array ( [e] => red [f] => green [g] => blue )
d) Array ( [a] => red [b] => green [c] => blue [d] => yellow [e] => red [f] => green [g] => blue )
View Answer

Answer: a
Explanation: The function array_intersect() compares the values of two (or more) arrays, and
returns the matches. So, in the above program values of a1 and a2 will be compared and the
values present in both the arrays will be the returned.

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

1. <?php
2. $a = array(12, 5, 2);
3. echo(array_product($a));
4. ?>

a) 024
b) 120
c) 010
d) 060
View Answer

Answer: b
Explanation: The array_product() function calculates and returns the product of an array.

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

1. <?php
2. $a = array("a" => "Jaguar", "b" => "Land Rover",
3. "c" => "Audi", "d" => "Maseratti");
4. echo array_search("Audi", $a);
5. ?>

a) a
b) b
c) c
d) d
View Answer
Answer: c
Explanation: The array_search() function searches for the element and returns the key of that
element.

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

1. <?php
2. $city_west = array("NYC", "London");
3. $city_east = array("Mumbai", "Beijing");
4. print_r(array_replace($city_west, $city_east));
5. ?>

a) Array ( [1] => Mumbai [0] => Beijing )


b) Array ( [0] => NYC [1] => London )
c) Array ( [1] => NYC [0] => London )
d) Array ( [0] => Mumbai [1] => Beijing )
View Answer

Answer: d
Explanation: The function array_replace() replaces the values of the first array with the values
from following arrays. So, in the above program the values of city_west will be replaced with
city_east.

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

1. <?php
2. $people = array("Peter", "Susan", "Edmund", "Lucy");
3. echo pos($people);
4. ?>

a) Lucy
b) Peter
c) Susan
d) Edmund
View Answer

Answer: b
Explanation: The pos() function returns the value of the current element in an array, and since no
operation has been done, the current element is the first element.

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

1. <?php
2. $number = range(0, 5);
3. print_r ($number);
4. ?>

a) Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
b) Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 )
c) Array ( [0] => 5 [1] => 5 [2] => 5 [3] => 5 [4] => 5 [5] => 5 )
d) Array ( [0] => 0 [5] => 5 )
View Answer

Answer: a
Explanation: The range() function creates an array containing a range of elements.
40. What will be the output of the following PHP code?
1. <?php
2. $array = array("red", "green");
3. array_push($array, "blue", "yellow");
4. print_r($array);
5. ?>

a) Array ( [0] => red [1] => green [2] => blue [3] => yellow )
b) Array ( [0] => blue [1] => yellow [2] => red [3] => green )
c) Array ( [0] => red [1] => green )
d) Array ( [0] => blue [1] => yellow )
View Answer

Answer: a
Explanation: The function array_push() inserts one or more elements to the end of an array. So,
in the above program blue and yellow will be inserted after previous values.

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

1. <?php
2. $age = array("Harry" => "21", "Ron" => "19", "Malfoy" => "23");
3. ksort($age);
4. foreach($age as $x => $x_value)
5. {
6. echo "Key=" . $x . ", Value=" . $x_value;
7. echo "<br>";
8. }
9. ?>

a)

Key = Harry, Value = 21


Key = Ron, Value = 21
Key = Malfoy, Value = 23

b)

Key = Harry, Value = 21


Key = Ron, Value = 19
Key = Malfoy, Value = 23

c)

Key = Harry, Value = 21


Key = Malfoy, Value = 23
Key = Ron, Value = 19

d)

Key = Ron, Value = 19


Key = Harry, Value = 21
Key = Malfoy, Value = 23
View Answer
Answer: c
Explanation: The ksort() function sorts an associative array in ascending order, according to the
key.

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

1. <?php
2. $cars = array("Volvo", "BMW", "Toyota");
3. echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
4. ?>

a) I like Volvo BMW and Toyota.


b) I like Volvo, BMW and Toyota)
c) I like Volvo, BMW and Toyota.
d) I like. Volvo.,. BMW. and. Toyota)
View Answer

Answer: b
Explanation: The array() function is used to create an array. Each elements are assigned ab index
as the rule of an array. So, calling $cars[0] will print element at index 0 and so on.

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

1. <?php
2. $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
3. print_r(array_change_key_case($age, CASE_UPPER));
4. ?>

a) Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )


b) Array ( [peter] => 35 [ben] => 37 [joe] => 43 )
c) Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
d) Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )
View Answer

Answer: c
Explanation: The array_change_key_case() function changes all keys in an array to lowercase or
uppercase.

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


1. <?php
2. $cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes", "Opel");
3. print_r(array_chunk($cars, 2));
4. ?>

a) Array ( [0] => Array ( [1] => Volvo [2] => BMW ) [1] => Array ( [1] => Toyota [2] =>
Honda ) [2] => Array ( [1] => Mercedes [2] => Opel ) )
b) Array ( [1] => Array ( [1] => Volvo [2] => BMW ) [2] => Array ( [1] => Toyota [2] =>
Honda ) [3] => Array ( [1] => Mercedes [2] => Opel ) )
c) Array ( [0] => Array ( [0] => Volvo [1] => Volvo ) [1] => Array ( [0] => BMW [1] => BMW
) [2] => Array ( [0] => Toyota [1] => Toyota ) )
d) Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] =>
Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )
View Answer

Answer: d
Explanation: The array_chunk() function splits an array into chunks of new arrays.

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

1. <?php
2. $fname = array("Peter", "Ben", "Joe");
3. $age = array("35", "37", "43");
4. $c = array_combine($fname, $age);
5. print_r($c);
6. ?>

a) Array ( Peter Ben Joe )


b) Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
c) Array ( 35 37 43 )
d) Array ( “[Peter] => 35” “[Ben] => 37” “[Joe] => 43” )
View Answer

Answer: b
Explanation: The array_combine() function creates an array by using the elements from one
“keys” array and one “values” array.

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

1. <?php
2. $a = array("A", "Cat", "Dog", "A", "Dog");
3. print_r(array_count_values($a));
4. ?>

a) Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )


b) Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )
c) Array ( [A] => 1 [Cat] => 1 [Dog] => 2 )
d) Array ( [A] => 2 [Cat] => 1 [Dog] => 1)
View Answer
Answer: a
Explanation: The array_count_values() function counts all the values of an array.

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

1. <?php
2. $a1 = array("a"=>"red", "b"=>"green", "c"=>"blue", "d"=>"yellow");
3. $a2 = array("e"=>"red", "f"=>"green", "g"=>"blue");
4. $result = array_diff($a1, $a2);
5. print_r($result);
6. ?>

a) Array ( [d] => yellow )


b) Array ( [c] => blue )
c) Array ( [a] => red )
d) Array ( [e] => yellow )
View Answer

Answer: a
Explanation: The array_diff() function compares the values of two (or more) arrays, and returns
the differences.

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

1. <?php
2. $a1 = array_fill(3, 4, "blue");
3. $b1 = array_fill(0, 1, "red");
4. print_r($a1);
5. echo "<br>";
6. print_r($b1);
7. ?>

a)

Array ( [3] => blue [4] => blue)


Array ( [0] => red )

b)

Array ( [4] => blue [5] => blue [6] => blue)
Array ( [0] => red )

c)

Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
Array ()

d)

Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
Array ( [0] => red )
View Answer
Answer: d
Explanation: The array_fill() function fills an array with values.

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

1. <?php
2. $a1 = array("red", "green");
3. $a2 = array("blue", "yellow");
4. print_r(array_merge($a1, $a2));
5. ?>

a) Array ( [0] => red [1] => green)


b) Array ( [0] => blue [1] => yellow [2] => red [3] => green )
c) Array ( [0] => red [1] => green [2] => blue [3] => yellow )
d) Array ( [0] => blue [1] => yellow )
View Answer

Answer: c
Explanation: The array_merge() function merges one or more arrays into one array.

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

1. <?php
2. $a = array("a"=>"red", "b"=>"green", "c"=>"blue");
3. echo array_shift($a);
4. print_r ($a);
5. ?>

a) green
b) red
c) redArray( [c] => green [c] => blue )
d) redArray( [b] => green [c] => blue )
View Answer

Answer: d
Explanation: The array_shift() function removes the first element from an array, and returns the
value of the removed element.

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

1. <?php
2. $a = array("red", "green", "blue");
3. array_pop($a);
4. print_r($a);
5. ?>
a) Array ( [0] => red [1] => green )
b) Array ( [0] => green [1] => blue )
c) Array ( [0] => red [1] => blue )
d) Array ( [0] => blue [1] => blue )
View Answer

Answer: a
Explanation: The array_pop() function deletes the last element of an array.

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

1. <?php
2. $fruits = array ("mango", "apple", "pear", "peach");
3. $fruits = array_flip($fruits);
4. echo ($fruits[0]);
5. ?>

a) mango
b) error
c) peach
d) 0
View Answer

Answer: b
Explanation: As we are flipping the values, $fruits[“mango”] = 0, $fruits[“apple”] = 1 and so on.

53. Which of the functions is used to sort an array in descending order?


a) sort()
b) asort()
c) rsort()
d) dsort()
View Answer

Answer: c
Explanation: The function sort() will sort the arrays in ascending order, the function rsort() will
sort arrays in descending order. While the function asort() will sort associative arrays in
ascending order, according to the value.

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

1. <?php
2. $fruits = array ("mango", "apple", "peach", "pear");
3. $fruits = asort ($fruits);
4. printr ($fruits);
5. ?>

a) Array ( [1] => apple [0] => mango [2] => peach [3] => pear )
b) Array ( [0] => apple [1] => mango [2] => peach [3] => pear )
c) Error
d) Array ( [1] => apple [0] => mango [3] => peach [2] => pear )
View Answer

Answer: c
Explanation: The program will give an error i.e. uncaught error: call to undefined function
printr(). As the correct function is print_r().

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

1. <?php
2. $arr = array ("picture1.JPG", "picture2.jpg",
3. "Picture10.jpg", "picture20.jpg");
4. sort($arr);
5. print_r($arr);
6. ?>

a) Array ( [0] => picture1.JPG [1] => Picture10.jpg [2] => picture2.jpg [3] => picture20.jpg )
b) Array ( [0] => picture1.JPG [1] => picture2.jpg [2] => Picture10.jpg [3] => picture20.jpg )
c) Array ( [0] => Picture10.jpg [1] => picture1.JPG [2] => picture2.jpg [3] => picture20.jpg )
d) Array ( [0] => Picture10.jpg [1] => picture1.JPG [2] => picture20.jpg [3] => picture2.jpg )
View Answer

Answer: c
Explanation: The function sort() in PHP sorts an indexed array in ascending order. While sorting,
each character is compared with the others and sorted using ASCII values.

56. Which function should we use to sort the array in natural order?
a) dsort()
b) casesort()
c) natcasesort()
d) naturalsort()
View Answer

Answer: c
Explanation: The function natcasesort() in PHP sorts an array by using a “natural order”
algorithm. All the values keep their original keys. Eg: In a natural algorithm, as the number 2 is
less than the number 10. But in computer sorting, 10 is less than 2, because the first number in
“10” is less than 2. The function is case-insensitive.

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

1. <?php
2. $face = array ("A", "J", "Q", "K");
3. $number = array ("2","3","4", "5", "6", "7", "8", "9", "10");
4. $cards = array_merge ($face, $number);
5. print_r ($cards);
6. ?>
a) Array ( [0] => A [1] => J [2] => Q [3] => K [4] => 2 [5] => 3 [6] => 4 [7] => 5 [8] => 6 [9]
=> 7 [10] => 8 [11] => 9 [12] => 10 )
b) Array ( [0] => A [1] => 2 [2] => J [3] => 3 [4] => Q [5] => 4 [6] => K [7] => 5 [8] => 6 [9]
=> 7 [10] => 8 [11] => 9 [12] => 10 )
c) Error
d) Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9]
=> A [10] => J [11] => Q [12] => K )
View Answer

Answer: a
Explanation: The array_merge() function merges one or more arrays into one array. The resulting
array will begin with the first input array parameter, appending each subsequent array parameter
in the order of appearance.

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

1. <?php
2. $fruits = array ("apple", "mango", "peach", "pear",
3. "orange");
4. $subset = array_slice ($fruits, 2);
5. print_r ($subset);
6. ?>

a) Array ( [0] => peach )


b) Array ( [0] => apple [1] => mango [2] => peach )
c) Array ( [0] => apple [1] => mango )
d) Array ( [0] => peach [1] => pear [2] => orange )
View Answer

Answer: d
Explanation: The array_slice() function returns a section of an array based on a starting and
ending offset value.
59. What will be the output of the following PHP code?
1. <?php
2. $fruits = array ("apple", "mango", "peach", "pear",
3. "orange");
4. $subset = array_splice ($fruits, 2);
5. print_r ($fruits);
6. ?>

a) Error
b) Array ( [0] => apple [1] => mango [2] => peach )
c) Array ( [0] => apple [1] => mango )
d) Array ( [0] => pear [1] => orange )
View Answer

Answer: c
Explanation: The array_splice() function removes all elements of an array found within a
specified range.
60. What will be the output of the following PHP code?

1. <?php
2. $number = array ("4", "hello", 2);
3. echo (array_sum ($number));
4. ?>

a) 4hello2
b) 4
c) 2
d) 6
View Answer

Answer: d
Explanation: The array_sum() function add all the values of the input array together, returning
the final sum. If a string datatype is found, it’ll be ignored.

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

1. <?php
2. $array1 = array ("KA", "LA", "CA", "MA", "TA");
3. $array2 = array ("KA", "IA", "CA", "GA", "TA");
4. $inter = array_intersect ($array1, $array2);
5. print_r ($inter);
6. ?>

a) Array ( [0] => KA [1] => LA [2] => CA [3] => MA [4] => TA [5] => IA [6] => GA )
b) Array ( [0] => KA [2] => CA [4] => TA )
c) Array ( [1] => IA [3] => GA )
d) Array ( [1] => LA [3] => MA )
View Answer

Answer: b
Explanation: The array_intersect() function returns a key preserved array consisting only of those
values present in the first array that are also present in each of the other input arrays.
PHP Array MCQs
.
1. How many types of array are available in php?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : C

Explanation: There are basically three types of arrays in PHP: Indexed or Numeric Arrays, Associative Arrays, Multidimensional
Arrays

2. By default, the index of array in php starts from ______?


A. 0
B. 1
C. -1
D. 2
View Answer
Ans : A

Explanation: By default, the index starts from zero.

3. A ________ is an array with more than two dimensions.


A. single dimensional array
B. multi dimensional array
C. Both A and B
D. None of the above
View Answer
Ans : B

Explanation: A multidimensional array is an array with more than two dimensions. In a matrix, the two dimensions are represented
by rows and columns

4. Which of the following are correct ways of creating an array?


i) arr[0] = "letsfindcourse";
ii) $arr[] = array("letsfindcourse");
iii) $arr[0] = "letsfindcourse";
iv) $arr = array("letsfindcourse");
A. ii), iii) and iv)
B. ii) and iii)
C. Only i)
D. iii) and iv)
View Answer
Ans : D

Explanation: A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when
you use the array(), constructor.

5. Which in-built function will add a value to the end of an array?


A. array_unshift()
B. into_array()
C. inend_array()
D. array_push()
View Answer
Ans : D

Explanation: array_push adds value to the end of an array, returning the total count of elements in the array after the new value has
been added.

6. Which function returns an array consisting of associative key/value pairs?


A. count()
B. array_count()
C. array_count_values()
D. count_values()
View Answer
Ans : C

Explanation: The function array_count_values() will count all the values of an array.

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

<?php

$arr = array ("lets", "find", "course", ".Com");

echo (array_search (".com", $arr) );

?>
A. 0
B. Garbage value
C. 3
D. No Output
View Answer
Ans : D

Explanation: Due to case-sensitive .com is not in an array so there will be no output.


8. As compared to associative arrays vector arrays are much
A. Faster
B. Slower
C. Stable
D. None of the above
View Answer
Ans : A

Explanation: As compared to associative arrays vector arrays are much Faster.

9. What is the output of the following php code?

<?php

$alphabet = array ("A", "B", "C");

echo (next($alphabet));

?>
A. A
B. B
C. C
D. Error
View Answer
Ans : B

Explanation: The next function is an in-built function used to print the next value of the current index. As the current index value is 0
so next will print value B.

10. What is the output of the following php code?

<?php

$alphabet = array("A" => array

( "php" => "php 7.0", "date" => "3 December 2019"),

"B" => array( "python" => "python 3.8.2",

"date" => "24 December 2019") );

echo $alphabet ["A"]["date"];


?>
A. php 7.0
B. 3 December 2019
C. python 3.8.2
D. 24 December 2019
View Answer
Ans : B

Explanation: The output of the following PHP code is 3 December 2015.


11. Keys in array can be non-sequential.
A. True
B. False
C. Depend on program
D. Keys does not exist in array
View Answer
Ans : A

Explanation: Keys in an array can be non-sequential.

12. Key/value pair can be initialized using = operator?


A. True
B. False
C. Depend on program
D. Keys does not exist in array
View Answer
Ans : A

Explanation: Key/value pair can be initialized using = operator

13. What is the use of is_array() function?


A. Function is used to print the array in readable format.
B. Adds elements to the beginning of the array and returns the size of array.
C. Function can be used to verify if a variable is an array. Returns TRUE or FALSE
D. Adds elements to the end of the array and returns the size of array.
View Answer
Ans : C

Explanation: is_array() Function can be used to verify if a variable is an array. Returns TRUE or FALSE.

14. What is the use of array_unshift() function?


A. Function is used to print the array in readable format.
B. Adds elements to the beginning of the array and returns the size of array.
C. Function can be used to verify if a variable is an array. Returns TRUE or FALSE
D. Adds elements to the end of the array and returns the size of array.
View Answer
Ans : B

Explanation: array_unshift() Adds elements to the beginning of the array and returns the size of array.
15. What is the use of array_flip() function?
A. Rearranges the array elements in the reverse order
B. Is used to convert the keys to values and values to keys.
C. Can be used to fetch the keys present in the array
D. Returns number of elements in the array
View Answer
Ans : B

Explanation: array_flip() Is used to convert the keys to values and values to keys.

16. What is the use of array_values() function?


A. Returns all the values of the respective keys present in the passed array
B. Returns number of elements in the array
C. Can be used to fetch the keys present in the array
D. Returns the values and the frequency of each value in form of an array.
View Answer
Ans : D

Explanation: array_count_values() Returns the values and the frequency of each value in form of an array.

17. Predict the output of the following code.

<?php

$a=array(1,2,3,5,6);

next($a);

next($a);

next($a);

echo current($a);

?>
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : D

Explanation: 5 is the output of the following code.

18. Predict the output of the following PHP code.


<?php

$fruits = array ("apple", "orange", "banana", "guava", "pine-


apple", "papaya", "melon");

next($fruits);

next($fruits);

prev($fruits);

?>
A. guava
B. banana
C. orange
D. pine-apple
View Answer
Ans : C

Explanation: orange be the output of the following PHP code.

19. Which of the following function is used to get the value of the previous element in an array?
A. last()
B. before()
C. prev()
D. previous()
View Answer
Ans : C

Explanation: The prev() function returns the previous element in the array.

20. Which of the following function is Used to set the array pointer to the value of last key?
A. last()
B. end()
C. next()
D. final()
View Answer
Ans : B

Explanation: The end() function is Used to set the array pointer to the value of last key.

22. As compared to associative arrays vector arrays are much

a. Faster

b. Slower

c. Stable

d. None of them
Answer: (a).Faster

23. Other than index values an array can be retrieved by a function that is called as

a. Retrieve ( ) function

b. Array_retrive ( ) function

c. list ( ) function

d. Array_call ( ) function

Answer: (c).list ( ) function

24. Multidimensional arrays are simple arrays that have

a. One dimensional

b. Many arrays stored in them

c. No indexes

d. 1 element

Answer: (b).Many arrays stored in them

25. Three ways to create an array is Direct assignment, array ( ) construct and

a. Functions returning arrays

b. Functions creating arrays

c. Keys creating arrays

d. None of them

Answer: (a).Functions returning arrays

26. Which of the following are correct ways of creating an array?

i) state[0] = “karnataka”;
ii) $state[] = array(“karnataka”);
iii) $state[0] = “karnataka”;
iv) $state = array(“karnataka”);

a. iii) and iv)

b. ii) and iii)

c. Only i)

d. ii), iii) and iv)

Answer: (a).iii) and iv)

27. What will be the output of the following php code?

<?php
$states = array("karnataka" => array

( "population" => "11,35,000", "capital" => "Bangalore"),


"Tamil Nadu" => array( "population" => "17,90,000",

"capital" => "Chennai") );


echo $states["karnataka"]["population"];
?>

a. karnataka 11,35,000

b. 11,35,000

c. population 11,35,000

d. karnataka population

Answer: (b).11,35,000

28. Which function will return true if a variable is an array or false if it is not?

a. this_array()

b. is_array()

c. do_array()

d. in_array()

Answer: (b).is_array()

29. Which in-built function will add a value to the end of an array?

a. array_unshift()

b. into_array()

c. inend_array()

d. array_push()

Answer: (d).array_push()
30. What will be the output of the following PHP code?

<?php
$state = array ("Karnataka", "Goa", "Tamil Nadu",

"Andhra Pradesh");
echo (array_search ("Tamil Nadu", $state) );

?>

a. True

b. 1

c. False

d. 2

Answer: (d).2

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


<?php
$fruits = array ("apple", "orange", "banana");
echo (next($fruits));
echo (next($fruits));
?>

a. orangebanana

b. appleorange

c. orangeorange

d. appleapple

Answer: (a).orangebanana

32. Which function can be used to move the pointer to the previous array position?

a. last()

b. before()

c. prev()

d. previous()
Answer: (c).prev()

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


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

a. 3

b. 4

c. 5

d. 6

Answer: (d).6

34. Which function returns an array consisting of associative key/value pairs?

a. count()

b. array_count()

c. array_count_values()

d. count_values()

Answer: (c).array_count_values()

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


<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[2] . ", " . $cars[1] . " and " . $cars[0] .
".";
?>

a. like Volvo, Toyota and BMW

b. I like Volvo, BMW and Toyota

c. I like BMW, Volvo and Toyota

d. I like Toyota, BMW and Volvo

Answer: (d).I like Toyota, BMW and Volvo


36. What will be the output of the following PHP code?
<?php
$fname = array("Peter", "Ben", "Joe");
$age = array("35", "37", "43");
$c = array_combine($age, $fname);
print_r($c);
?>

a. Array ( Peter Ben Joe )

b. Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )

c. Array ( 35 37 43 )

d. Array ( [35] => Peter [37] => Ben [43] => Joe )

Answer: (d).Array ( [35] => Peter [37] => Ben [43] => Joe )

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


<?php
$a=array("A","Cat","Dog","A","Dog");
$b=array("A","A","Cat","A","Tiger");
$c=array_combine($a,$b);
print_r(array_count_values($c));
?>

a. Array ( [A] => 5 [Cat] => 2 [Dog] => 2 [Tiger] => 1 )

b. Array ( [A] => 2 [Cat] => 2 [Dog] => 1 [Tiger] => 1 )

c. Array ( [A] => 6 [Cat] => 1 [Dog] => 2 [Tiger] => 1 )

d. Array ( [A] => 2 [Cat] => 1 [Dog] => 4 [Tiger] => 1 )

Answer: (a).Array ( [A] => 5 [Cat] => 2 [Dog] => 2 [Tiger] => 1 )

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


<?php
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" =>
"yellow");
$a2 = array("e" => "red", "f" => "green", "g" => "blue", "h" =>
"orange");
$a3 = array("i" => "orange");
$a4 = array_combine($a2, $a3);
$result = array_diff($a4, $a2);
print_r($result);
?>

a. Array ( [d] => yellow )

b. Array ( [i] => orange )

c. Array ( [h] => orange )

d. Array ( [d] => yellow [h] => orange )

Answer: (a).Array ( [d] => yellow )

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


<?php
$a1 = array("red", "green");
$a2 = array("blue", "yellow");
$a3 = array_merge($a1, $a2);
$a4 = array("a", "b", "c", "d");
$a = array_combine($a4, $a3);
print_r($a);
?>

a. Array ( [a] => blue [b] => yellow [c] => red [d] => green )

b. Array ( [0] => blue [1] => yellow [2] => red [3] => green )

c. Array ( [0] => red [1] => green [2] => blue [3] => yellow )

d. Array ( [a] => red [b] => green [c] => blue [d] => yellow )

Answer: (d).Array ( [a] => red [b] => green [c] => blue [d] => yellow )

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


<?php
$a = array("a" => "india", "b" => "brazil", "c" => "china");

echo array_shift($a);
echo "<br>"
array_pop($a);
print_r($a);
?>

a. india
Array ( [a] => china )

b. india
Array ( [a] => brazil )

c. china
Array ( [a] => india )

d. china
Array ( [a] => brazil )

Answer: (b).india
Array ( [a] => brazil )

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


<?php
$a1 = array_fill(1, 4, "hello");
$b1 = array_fill(5, 1, "php");

$a2 = array_merge($a1, $a2);


print_r($a2);
echo "<br>";
print_r($b1);
?>

a. Array ( [1] => hello [4] => hello [5] => php )

b. Array ( [1] => hello [2] => hello [3] => hello [4] => hello )

c. Array ( [1] => hello [2] => hello [3] => hello [4] => hello [5] => php )

d. Array ( [1] => hello [2] => hello [3] => hello [4] => hello )

Answer: (c).Array ( [1] => hello [2] => hello [3] => hello [4] => hello [5] => php )

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


<?php
$names = array("Sam", "Bob", "Jack");
echo $names[0] . "is the brother of " . $names[1] . " and " .
$names[1] . ".";

?>

a. Sam is the brother of Bob and Jack

b. Sam is the brother of Jack and Bob

c. Sam is the brother of Jack and Bob

d. Error

Answer: (c).Sam is the brother of Jack and Bob

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


<?php
$names = array("Sam", "Bob", "Jack");
echo $names[0] . "is the brother of " . $names[1] . " and " .
$names[1] . ".".$brother;
?>

a. Sam is the brother of Bob and Bob) $brother

b. Sam is the brother of Bob and Bob)

c. $brother

d. Error

Answer: (d).Error

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


<?php
$place = array("NYC", "LA", "Paris");
array_pop($place);
$place1 = array("Paris");
$place = array_merge($place, $place1);
print_r($place);
?>
a. Array ( [0] => LA [1] => Paris [2] => Paris )

b. Array ( [0] => NYC [1] => LA [2] => Paris)

c. Array ( [0] => NYC [1] => LA [2] => Paris [3] => Paris )

d. None of the mentioned

Answer: (a).Array ( [0] => LA [1] => Paris [2] => Paris )

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


<?php
$age = array("Harry" => "21", "Ron" => "23","Malfoy" => "21");
array_change_key_case($age, CASE_UPPER);
array_pop($age);
print_r($age);
?>

a. Array ( [Harry] => 21 [Ron] => 23 [Malfoy] => 21 )

b. Array ( [HARRY] => 21 [RON] => 23 [MALFOY] => 21 )

c. Array ( [HARRY] => 21 [RON] => 23 )

d. Array ( [Harry] => 21 [Ron] => 23 )

Answer: (c).Array ( [HARRY] => 21 [RON] => 23 )

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


<?php
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" =>
"yellow");
$result = array_flip($a1);
print_r($result);
?>

a. Array ( [red] => red [green] => green [blue] => blue [yellow] => yellow )

b. Array ( [a] => a [b] => b [c] => c [d] => d )

c. Array ( [red] => a [green] => b [blue] => c [yellow] => d )

d. Array ( [a] => red [b] => green [c] => blue [d] => yellow )

Answer: (c).Array ( [red] => a [green] => b [blue] => c [yellow] => d )
47. What will be the output of the following PHP code ?
<?php
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" =>
"yellow");
$a2 = array("e" => "red","f" => "green", "g" => "blue");

$result = array_intersect($a1, $a2);


print_r($result);
?>

a. Array ( [a] => red [b] => green [c] => blue )

b. Array ( [a] => red [b] => green [c] => blue [d] => yellow )

c. Array ( [e] => red [f] => green [g] => blue )

d. Array ( [a] => red [b] => green [c] => blue [d] => yellow [e] => red [f] => green [g] => blue )

Answer: (a).Array ( [a] => red [b] => green [c] => blue )

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


<?php
$a = array(12, 5, 2);
echo(array_product($a));
?>

a. 024

b. 120

c. 010

d. 060

Answer: (b).120

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


<?php
$a = array("a" => "Jaguar", "b" => "Land Rover", "c" => "Audi",
"d" => "Maseratti");
echo array_search("Audi", $a);
?>

a. a
b. b

c. c

d. d

Answer: (c).c

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


<?php
$city_west = array("NYC", "London");
$city_east = array("Mumbai", "Beijing");

print_r(array_replace($city_west, $city_east));
?>

a. Array ( [1] => Mumbai [0] => Beijing )

b. Array ( [0] => NYC [1] => London )

c. Array ( [1] => NYC [0] => London )

d. Array ( [0] => Mumbai [1] => Beijing )

Answer: (d).Array ( [0] => Mumbai [1] => Beijing )

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


<?php
$people = array("Peter", "Susan", "Edmund", "Lucy");
echo pos($people);
?>

a. Lucy

b. Peter

c. Susan

d. Edmund

Answer: (b).Peter

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


<?php
$number = range(0, 5);

print_r ($number);
?>

a. Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )

b. Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 )

c. Array ( [0] => 5 [1] => 5 [2] => 5 [3] => 5 [4] => 5 [5] => 5 )

d. Array ( [0] => 0 [5] => 5 )

Answer: (a).Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )

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


<?php
$array = array("red", "green");
array_push($array, "blue", "yellow");
print_r($array);
?>

a. Array ( [0] => red [1] => green [2] => blue [3] => yellow )

b. Array ( [0] => blue [1] => yellow [2] => red [3] => green )

c. Array ( [0] => red [1] => green )

d. Array ( [0] => blue [1] => yellow )

Answer: (a).Array ( [0] => red [1] => green [2] => blue [3] => yellow )

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


<?php
$age = array("Harry" => "21", "Ron" => "19", "Malfoy" => "23");
ksort($age);
foreach($age as $x => $x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";

}
?>

a. Key = Harry, Value = 21


Key = Ron, Value = 21
Key = Malfoy, Value = 23
b. Key = Harry, Value = 21
Key = Ron, Value = 19
Key = Malfoy, Value = 23

c. Key = Harry, Value = 21


Key = Malfoy, Value = 23
Key = Ron, Value = 19

d. Key = Ron, Value = 19


Key = Harry, Value = 21
Key = Malfoy, Value = 23

Answer: (c).Key = Harry, Value = 21


Key = Malfoy, Value = 23
Key = Ron, Value = 19

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


<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
print_r(array_change_key_case($age, CASE_UPPER));
?>

a. Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )

b. Array ( [peter] => 35 [ben] => 37 [joe] => 43 )

c. Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )

d. Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )

Answer: (c).Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )

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


<?php
$cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes",
"Opel");
print_r(array_chunk($cars, 2));

?>

a. Array ( [0] => Array ( [1] => Volvo [2] => BMW ) [1] => Array ( [1] => Toyota [2] => Honda ) [2] => Array ( [1] => Mercedes [ 2] => Opel
))

b. Array ( [1] => Array ( [1] => Volvo [2] => BMW ) [2] => Array ( [1] => Toyota [2] => Honda ) [3] => Array ( [1] => Mercedes [2] => Opel
))

c. Array ( [0] => Array ( [0] => Volvo [1] => Volvo ) [1] => Array ( [0] => BMW [1] => BMW ) [2] => Array ( [0] => Toyota [1] => Toyota ) )

d. Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [ 1] => Opel
))

Answer: (d).Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1]
=> Opel ) )
57. What will be the output of the following PHP code?
<?php
$fname = array("Peter", "Ben", "Joe");
$age = array("35", "37", "43");
$c = array_combine($fname, $age);
print_r($c);
?>

a. Array ( Peter Ben Joe )

b. Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )

c. Array ( 35 37 43 )

d. Array ( “[Peter] => 35” “[Ben] => 37” “[Joe] => 43” )

Answer: (b).Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )

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


<?php
$a = array("A", "Cat", "Dog", "A", "Dog");
print_r(array_count_values($a));
?>

a. Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )

b. Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )

c. Array ( [A] => 1 [Cat] => 1 [Dog] => 2 )

d. Array ( [A] => 2 [Cat] => 1 [Dog] => 1)

Answer: (a).Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )

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


<?php
$a1 = array("a"=>"red", "b"=>"green", "c"=>"blue", "d"=>"yellow");
$a2 = array("e"=>"red", "f"=>"green", "g"=>"blue");
$result = array_diff($a1, $a2);
print_r($result);
?>

a. Array ( [d] => yellow )

b. Array ( [c] => blue )

c. Array ( [a] => red )

d. Array ( [e] => yellow )

Answer: (a).Array ( [d] => yellow )

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


<?php
$a1 = array_fill(3, 4, "blue");
$b1 = array_fill(0, 1, "red");
print_r($a1);
echo "<br>";
print_r($b1);
?>

a. Array ( [3] => blue [4] => blue)

b. Array ( [4] => blue [5] => blue [6] => blue)

c. Array ( [3] => blue [4] => blue [5] => blue [6] => blue )

d. Array ( [3] => blue [4] => blue [5] => blue [6] => blue )

Answer: (d).Array ( [3] => blue [4] => blue [5] => blue [6] => blue )

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

<?php

$state = array ("Karnataka", "Goa", "Tamil Nadu",

"Andhra Pradesh");

echo (array_search ("Tamil Nadu", $state) );

?>
a) True
b) 1
c) 2
d) False

Answer: c
Explanation: The array_search() function searches an array for a specified value, returning its key if located and
FALSE otherwise.

62. Which in-built function will add a value to the end of an array?

a) array_unshift()
b) array_push()
c) inend_array()
d) into_array()

Answer: b
Explanation: array_push adds a value to the end of an array, returning the total count of elementsin the array after
the new value has been added.

63. Which function will return true if a variable is an array or false if it is not?

a) this_array()
b) in_array()
c) do_array()
d) is_array()

Explanation: A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean
is_array(mixed variable).

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

<?php

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

echo (next($fruits));

echo (next($fruits));

?>

a) orangeorange
b) appleorange
c) orangebanana
d) appleapple

Answer: c
Explanation: The next() function returns the array value residing at the position immediately following that of the
current array pointer.

65. Which function can be used to move the pointer to the previous array position?
a) last()
b) before()
c) previous()
d) prev()

Answer: d
Explanation:None.

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

<?php

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

"banana");

echo (count($fruits, 1));

?>

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

Answer: a
Explanation:The array entity holding pear and mango is counted as an item, just as its contents are.

67. Which function returns an array consisting of associative key/value pairs?

a) count()
b) array_count_values()
c) array_count()
d) count_values()

Answer: b
Explanation:None.
Sanfoundry Global Education &

68. PHP’s numerically indexed array begin with position __.

a) 0
b) 1
c) 2
d) -1

Answer: a
Explanation: Like many programming languages, the first element of an array has an index value of 0.

69. Which of the following are correct ways of creating an array?

i) state[0] = “karnataka”;
ii) $state[] = array(“karnataka”);
iii) $state[0] = “karnataka”;
iv) $state = array(“karnataka”);

a) iii) and iv)


b) ii) and iii)
c) Only i)
d) ii), iii) and iv)
Explanation: A variable name should start with $ symbol which is not present in i) and you need not put the square
brackets when you use the array() constructor.

70. What will be the output of the following php code?

<?php

$states = array("karnataka" => array

( "population" => "11,35,000", "captial" => "Bangalore"),

"Tamil Nadu" => array( "population" => "17,90,000",

"captial" => "Chennai") );

echo $states["karnataka"]["population"];

?>

a) 11,35,000
b) karnataka 11,35,000
c) population 11,35,000
d) karnataka population

Answer: a
Explanation: Treat states as a multidimensional array and accordingly traverse it to get the value.
1. In how many ways we can create strings in PHP?

A. 1
B. 2
C. 3
D. 4
Ans : B

Explanation: There are two ways of creating strings in PHP: single quote and double
quote

2. Which type of string can processes special characters inside


quotes?
A. single quote string
B. double quote string
C. Both A and B
D. None of the above

Ans : B

Explanation: double-quote strings in PHP is capable of processing special characters.

3. Which of the following is not a Built-in String functions in php?


A. strlen()
B. str_replace()
C. strpos()
D. strreverse()

Ans : D

Explanation: strreverse() function is not a Built-in String functions in php.

4. Why trim() function is used in php?


A. to remove whitespaces
B. to remove lowercase alphabet
C. to remove uppercase alphabet
D. to remove underscore

Ans : A
Explanation: This trim() function allows us to remove whitespaces or strings from both
sides of a string.

5. Which of the following is the output of the below code?

<?php

echo strpos("Hello letsfindcourse!", "lets"), " \n";

?>

A. 4
B. 5
C. 6
D. 7
Ans : C

Explanation: 6 is the output of the following code.

6. Which of the following is the output of the below code?

<?php

var_dump(strpos("Hello letsfindcourse!", "course"));

?>

A. int(13)
B. char(14)
C. int(14)
D. int(15)
Ans : C

Explanation: int(14) is the output of the following code.

7. Which is true about var_dump() function?


A. var_dump() loops infinitely
B. var_dump() cuts off loop afetr getting same element two times
C. var_dump() cuts off loop after getting the same element three times
D. var_dump() cuts off loop after getting the same element five times
Ans : C

Explanation: var_dump() cuts off loop after getting the same element three times is true
about var_dump() function.

8. The ________ function compares the two strings s1 and s2,


ignoring the case of the characters.
A. strtolower()
B. toLowerCase()
C. strcasecmp()
D. lc()

Ans : C

Explanation: The strcasecmp() function compares the two strings s1 and s2, ignoring the
case of the characters.

9. Returns a string arguments with trilling blank space removed,


is a behavior of
A. starts( ) function
B. chop( ) function
C. rtrim( ) function
D. lc()
Ans : D

Explanation: Returns a string arguments with trilling blank space removed, is a behavior
of chop ( ) function and rtrim ( ) function

10. What is the output of the following php code?

<?php

$username = "letsfindcourse";

if (preg_match("([^a-z])",$username))

echo "Name must be all lowercase!";

else

echo "Name is all lowercase!";


?>

A. Error
B. No Output
C. Name must be all lowercase!
D. Name is all lowercase!

Ans : D

11. Predict the output of the following code snippet :

<?php
$str="chess was played";
echo strlen(substr($str,3,2))."
"
?>
A. 1
B. 2
C. 3
D. Array

Ans : B

Explanation: 2 the output of the following code snippet.

12. Predict the output of the following code snippet :

<?php
echo count_chars("AA",1);
?>
A. 2
B. [65]=>2
C. Array
D. None of the above
Ans : C

Explanation: Array will be the output of the following statement

13. A variable $str is set to "HELLO WORLD", which of the following script returns
it title case?

A. echo ucwords($str)
B. echo ucwords(strtolower($str)
C. echo ucfirst($str)
D. echo ucfirst(strtolower($str)

Ans : B

Explanation: echo ucwords(strtolower($str) script returns it title case.

14. The PHP function searches for a specific text within a string.

A. strpos()
B. strposition()
C. strrev()
D. str_replace()

Ans : A

Explanation: The PHP strpos() function searches for a specific text within a string.

15. Which function is used to Calculate a 32-bit CRC for a string?

A. crc32()
B. crypt()
C. heb32()
D. heb32c()

Ans : A

Explanation: crc32() function is used to Calculate a 32-bit CRC for a string.

16. What is the use of htmlentities() function in php?

A. Converts characters to HTML entities


B. Converts HTML entities to characters
C. Converts some predefined HTML entities to characters
D. Converts some predefined characters to HTML entities

Ans : A

Explanation: The use of htmlentities() function in php is to Converts characters to HTML entities

17. How many functions does PHP offer for searching and modifying strings using
Perl-compatible regular expressions.

A. 7
B. 8
C. 9
D. 10

Ans : B

Explanation: The functions are preg_filter(), preg_grep(), preg_match(), preg_match_all(),


preg_quote(), preg_replace(), preg_replace_callback(), and preg_split().
18. What will be the output of the following PHP code?

<?php
$title = "O malley wins the heavyweight championship!";
echo ucwords($title);
?>
A. O Malley Wins The Heavyweight Championship!
B. O malley Wins The Heavyweight Championship!
C. O Malley wins the heavyweight championship!
D. o malley wins the heavyweight championship!

Ans : D
Explanation: The ucwords() function capitalizes the first letter of each word in a string. Its prototype
follows:string ucwords(string str)

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

<?php
$url = "lfc123456@example.com";
echo ltrim(strstr($url, "@"),"@");
?>
A. lfc123456@example.com
B. lfc123456
C. lfc123456@
D. example.com

Ans : D

Explanation: The strstr() function returns the remainder of a string beginning with the first
occurrence of a predefined string.
20. How many functions does PHP offer for searching strings using POSIX style
regular expression?

A. 7
B. 8
C. 9
D. 10

Ans : A

Explanation: ereg(), ereg_replace(), eregi(), eregi_replace(), split(), spliti(), and sql_regcase() are the
functions offered.
MODULE 1
LOOP
1. PHP supports ____ types of looping techniques?
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : C

Explanation: PHP supports four types of looping techniques.

2. How many main parameter are used in for loop?


A. 2
B. 3
C. 4
D. 1
View Answer
Ans : B

Explanation: There are three main parameters to the code, namely the initialization, the test
condition and the counter.

3. do-while loop is an _____ control loop ?


A. exit
B. exist
C. easy
D. entry
View Answer
Ans : A

Explanation: The do-while loop is an exit control loop which means that it first enters the
loop, executes the statements, and then checks the condition.
4. while loop is an _____ control loop ?
A. exit
B. exist
C. easy
D. entry
View Answer
Ans : D

Explanation: The while loop is also an entry control loop i.e., it first checks the condition at
the start of the loop and if it is true then it enters the loop.

5. foreach loop is used to iterate over ____?


A. number
B. object
C. function
D. array
View Answer
Ans : D

Explanation: for each loop: This loop is used to iterate over the array. For every counter of
the loop, an array element is assigned and the next counter is shifted to the next element.

6. Which loop evaluates the condition expression as Boolean, if it is true,


it executes the statements and when it is false it will terminate?
A. For loop
B. while loop
C. do-while loop
D. All of the above
View Answer
Ans : B

Explanation: While loop evaluates the condition expression as Boolean, if it is true, it


executes the statements and when it is false it will terminate.

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

<?php
for ($num = 1; $num <= 10; $num += 2) {

echo "$num ";

?>

A. 1 3 5 7 9
B. 1 2 3 4 5
C. 9 7 5 3 1
D. Error
View Answer
Ans : A

Explanation: the output of the following PHP code 1 3 5 7 9.

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

<?php

$num = 20;

while ($num < 12) {

$num += 2;

echo $num, "\n";

?>

A. Error
B. No Output
C. infinite loop
D. Only one garbage value
View Answer
Ans : B
Explanation: The output of the following PHP code is no output.

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

<?php

$num = 2;

do {

$num += 2;

echo $num, "\n";

} while ($num < 0);

?>

A. Error
B. No Output
C. infinite loop
D. 4
View Answer
Ans : D

Explanation: 4 is the output of the following code because a statement is executed at least
once on using the do-while loop.

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

<?php

$arr = array (10, 20, 30);

foreach ($arr as $val) {

echo "$val1 \n";

?>

A. 10 20 30
B. No Output
C. 10
D. undefined variable
View Answer
Ans : D

Explanation: undefined variable $var1 will be the output of the following PHP code.

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

<?php

do

print "LFC";

while(10);

print "I LOVE WEBSITE";

?>

A. LFC
B. I LOVE WEBSITE
C. LFC I LOVE WEBSITE
D. infinite loop
View Answer
Ans : D

Explanation: infinite loop be the output of the following PHP code

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

<?php

$a;
for ($a = -3; $a < -5; ++$a)

print $x++;

?>

A. -3-4-5
B. -3-4
C. No Output
D. infinite loop
View Answer
Ans : C

Explanation: No Output be the output of the following PHP code.

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

<?php

for ($a = 1; $a <= 10; $a++){

for ($b = 1; $b <= 5; $b++){

print "LFC

";

?>

A. Print "LFC" 10 times


B. Print "LFC" 50 times
C. Print "LFC" 5 times
D. Print "LFC" 1 times
View Answer
Ans : B

Explanation: Print "LFC" 50 times be the output of the following PHP code.
14. What will be the output of the following PHP code ?

<?php

for($num = 10; $num<=20; print ++$num)

print ++$num;

?>

A. 111213141516171819202122
B. 11121314151617181920
C. 1112131415161718192021
D. infinite loop
View Answer
Ans : A

Explanation: 111213141516171819202122 be the output of the following PHP code.

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

<?php

$i=-5;

while($i){

$i++;

if($i%2==0)

continue;

else

$i++;

}
echo($i);

?>

A. 4 to 20
B. -20
C. Null
D. infinite loop
View Answer
Ans : B

Explanation: -20 the output of the following code snippet.

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

<?php

for ($i = 0; $i < 4; $i++)

for ($j = 0; $j < 3; $j++)

if ($i > 1)

continue;

echo("Hi

");

?>

A. prints "Hi" 3 times


B. prints "Hi" 4 times
C. prints "Hi" 5 times
D. prints "Hi" 6 times
View Answer
Ans : D

Explanation: "Hi" 6 times he output of the following code snippet

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

<?php

$i = 0;

$j = 0;

first: while ($i < 2)

$i++;

while ($j < 3)

$j++;

echo("loop

");

if($j%2==0)

continue;

goto first;

?>

A. prints "loop" infinite times


B. prints "loop" 1 times
C. prints "loop" 2 times
D. prints "loop" 3 times
View Answer
Ans : D
Explanation: "loop" 3 times the output of the following code snippet.

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

<?php

for($i=0; $i<=5; $i++){

$i = $i+1;

echo "$i";

?>

A. 5
B. 6
C. 7
D. 8
View Answer
Ans : B

Explanation: 6 the output of the following code snippet.

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

<?php

$a = 10;

$b = $a>2?"Hi":"Bye";

echo "$b";

?>

A. HiBye
B. Bye
C. Hi
D. Error
View Answer
Ans : C

Explanation: Hi the output of the following code snippet.

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

<?php

$a = 0;

if($a > 1 );

echo "Sun";

echo "Moon";

?>

A. SunMoon
B. Sun
C. Moon
D. Error
View Answer
Ans : A
1. What will be the output of the following PHP code?

1. <?php
2. $i = 0;
3. for ($i)
4. {
5. print $i;
6. }
7. ?>

a)0
b)infinite loop
c)no output
d)error
View Answer
Answer:d
Explanation: Wrong syntax for for loop.

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

1. <?php
2. $colors = array("red","green","blue","yellow");
3. foreach ($colors as $value)
4. {
5. echo "$value <br>";
6. }
7. ?>

a)

red

green

blue

yellow

b)red
c)no output
derror
View Answer
Answer:a
Explanation: This runs a for loop for that array.
3. What will be the output of the following PHP code?

1. <?php
2. for ($x = 0; $x <= 10; $x++)
3. {
4. echo "The number is: $x <br>";
5. }
6. ?>

a)

The number is: 0

The number is: 1

The number is: 2

The number is: 3

The number is: 4

The number is: 5

The number is: 6

The number is: 7

The number is: 8

The number is: 9

The number is: 10

b)The number is: 0


c)no output
d)error
View Answer
Answer:a
Explanation: This runs a for loop from 0 to 10
4. What will be the output of the following PHP code?

1. <?php
2. for ($x = 0; $x <= 10; print ++$x)
3. {
4. print ++$x;
5. }
6. ?>

a)123456789101112
b)12345678910
c)1234567891011
d)infinite-loop
View Answer
Answer:a
Explanation: The value of x is incremented and printed twice before checking,this last loop it
prints 11 and 12.

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

1. <?php
2. for ($x = 1; $x < 10;++$x)
3. {
4. print "*\t";
5. }
6. ?>

a)**********
b)*********
c)***********
d)infinite-loop
View Answer
Answer:b
Explanation: Loop runs from 1 to 9 i.e 9 times.

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

1. <?php
2. for ($x = -1; $x < 10;--$x)
3. {
4. print $x;
5. }
6. ?>

a)123456789101112
b)12345678910
c)1234567891011
d)infinite-loop
View Answer
Answer:d
Explanation: The value of x is decremented thus making it an infinite loop.

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

1. <?php
2. $x;
3. for ($x = -3; $x < -5; ++$x)
4. {
5. print ++$x;
6. }
7. ?>

a)-3-4-5
b)-3-4
c)infinite-loop
d)no-output
View Answer
Answer:d
Explanation: The loop is not even entered as x is initially 0.

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

1. <?php
2. for ($i++; $i == 1; $i = 2)
3. print "In for loop ";
4. print "After loop\n";
5.
6. ?>

a)In for loop


b)After for loop
c)In for loopAfter for loop
d)Infinite loop
View Answer
Answer:c
Explanation: The loop runs only once as value of x is incremented.
9. What will be the output of the following PHP code?

1. <?php
2. for (1; $i == 1; $i = 2)
3. print "In for loop ";
4. print "After loop\n";
5. ?>

a)In for loop


b)After for loop
c)In for loopAfter for loop
d)Infinite loop
View Answer
Answer:b
Explanation: The loop does not run as i initialized in check statement will be zero.

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

1. <?php
2. for ($i == 2; ++$i == $i; ++$i)
3. print "In for loop ";
4. print "After loop\n";
5. ?>

a) In for loopIn for loopIn for loopIn for loop……infinitely


b) After for loopAfter for loopAfter for loop……..infinitely
c) In for loopAfter for loopIn for loopAfter for loopIn for loopAfter for loop…..infinitely
d) After for loop
View Answer
Answer: a
1. What will be the output of the following PHP code?

1. <?php
2. while()
3. {
4. print "hi";
5. }
6. ?>

a)infinite loop
b)hi
c)no output
d)error
View Answer
Answer:d
Explanation: The while loop cannot be defined without a condition.

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

1. <?php
2. do
3. {
4. print "hi";
5. }
6. while(0);
7. print "hello";
8. ?>

a)infinite loop
b)hihello
c)hello
d)error
View Answer
Answer:b
Explanation: The do while loop executes at least once as the condition is in the while loop.

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

1. <?php
2. $i = 0
3. do
4. {
5. print "hi";
6. $i++;
7. }
8. while ($i != 3);
9. ?>
a)

hi

hi

b) hi
c)

hi

hi

hi

hi

d)nooutput
View Answer
Answer:c
Explanation: The check happens after the increment,thus it prints until i = 4.

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

1. <?php
2. $i = 0
3. while ($i != 3)
4. {
5. print "hi";
6. $i++;
7. }
8. ?>

a)

hi

hi

b)

hi
hi

hi

c)

hi

hi

hi

hi

d)no output
View Answer
Answer:b
Explanation: The check happens before the increment, thus it prints until i = 3

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

1. <?php
2. $i = 0
3. while ($i < 3)
4. {
5. print "hi";
6. $i--;
7. }
8. print "hello"
9. ?>

a)

hi

hi

hello

b)

hi

hi
hi

hello

c)

hi

hi

hi

hi

hello

d)infinite loop
View Answer
Answer:d
Explanation: There is no increment of i making it infinite.

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

1. <?php
2. $i = 0
3. while ($i < 3)
4. {
5. $i++;
6. }
7. print $i;
8. ?>

a)2
b)3
c)0
d)1
View Answer
Answer:b
Explanation: The increment happens and then the check happens.
7. What will be the output of the following PHP code?

1. <?php
2. $i = 0
3. do
4. {
5. $i++;
6. }
7. while ($i < 3);
8. print $i;
9. ?>

a)2
b)3
c)0
d)1
View Answer
Answer:b
Explanation: The increment happens and then the check happens.

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

1. <?php
2. $i = 0
3. while ($i++)
4. {
5. print $i;
6. }
7. print $i;
8. ?>

a) 0
b) infinite loop
c) 01
d) 1
View Answer
Answer:d
Explanation: As it is a post increment, it checks and then does not enter the loop, thus prints
only 1.
9. What will be the output of the following PHP code?

1. <?php
2. $i = "";
3. while($i)
4. {
5. print "hi";
6. }
7. print "hello";
8. ?>

a)hello
b)infinite loop
c)hihello
d)error
View Answer
Answer:a
Explanation: While accept does not accept anything other than a 0 or any other number as
false and true.

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

1. <?php
2. $i = "";
3. while ($i)
4. {
5. print "hi";
6. }
7. while($i < 8)
8. $i++;
9. print "hello";
10. ?>

a)Hi is printed 8 times, hello 7 times and then hi 2 times


b)Hi is printed 10 times, hello 7 times
c)Hi is printed once, hello 7 times
d)Hi is printed once, hello 7 times and then hi 2 times
View Answer
Answer: d
BASICS OF PHP
1. The term PHP is an acronym for PHP:_______________.
A. Hypertext Preprocessor
B. Hypertext multiprocessor
C. Hypertext markup Preprocessor
D. Hypertune Preprocessor
View Answer
Ans : A

Explanation: The term PHP is an acronym for PHP: Hypertext Preprocessor.

2. PHP is a ____________ language?


A. user-side scripting
B. client-side scripting
C. server-side scripting
D. Both B and C
View Answer
Ans : C

Explanation: PHP is a server-side scripting language designed specifically for web


development.

3. Who among this is the founder of php language?


A. Tim Berners-Lee
B. Brendan Eich
C. Guido van Rossum
D. Rasmus Lerdorf
View Answer
Ans : D

Explanation: PHP as it is known today is actually the successor to a product named PHP/FI.
Created by Rasmus Lerdorf

4. In which year php was created?


A. 1993
B. 1994
C. 1995
D. 1996
View Answer
Ans : B

Explanation: PHP, as it is known today, is actually the successor to a product named


PHP/FI. Created in 1994.

5. PHP files have a default file extension of_______.


A. .html
B. .xml
C. .php
D. .hphp
View Answer
Ans : C

Explanation: To run a PHP file on the server, it should be saved as lfc.php

6. Which of the following is the correct syntax of php?


A. <?php >
B. <php >
C. ?php ?
D. <?php ?>
View Answer
Ans : D

Explanation: Each block of PHP code begins and ends by turning the PHP tag on and off to
tell the server that it needs to execute PHP in between.

7. Which of the following is the latest version of php?


A. 7.1
B. 7.2
C. 7.3
D. 7.4
View Answer
Ans : B

Explanation: Latest Version of PHP is 7.2 .

8. Which of the following is the Release date of latest version (7.2) of


php?
A. 27 November 2017.
B. 28 November 2017.
C. 29 November 2017.
D. 30 November 2017.
View Answer
Ans : D

Explanation: The Latest Version of PHP is 7.2 and the Release date is 30 November 2017.

9. Which of the below statements is equivalent to $sub -= $sub?


A. $sub = $sub
B. $sub = $sub -$sub
C. $sub = $sub - 1
D. $sub = $sub - $sub - 1
View Answer
Ans : B

Explanation: a -= b is an subtraction assignment whose outcome is a = a - b. Same can be


done with addition, multiplication, division etc.

10. Which statement will output $lfc on the screen?


A. echo "$lfc";
B. echo "$$lfc";
C. echo "/$lfc";
D. echo "$lfc;";
View Answer
Ans : A
11. Which of the below symbol is a newline character?
A. \r
B. \n
C. /r
D. /n
View Answer
Ans : B

Explanation: PHP treats \n as a newline character.

12. PHP files can contain ________ code.


A. text
B. HTML
C. python
D. Both A and B
View Answer
Ans : D

Explanation: PHP files can contain text, HTML, CSS, JavaScript, and PHP code.

13. which of the following is new operator added in PHP 7?


A. <=!
B. <=$
C. <=>
D. <=?
View Answer
Ans : C

Explanation: PHP 7 supports new operators (like the spaceship operator: <=> )

14. Which of the conditional statements is/are supported by PHP?


i) if statements
ii) if-else statements
iii) if-elseif statements
iv) switch statements
A. Only i)
B. i), ii) and iv)
C. ii), iii) and iv)
D. i), ii), iii) and iv)
View Answer
Ans : D

Explanation: All are conditional statements supported by PHP as all are used to evaluate
different conditions during a program and take decisions based on whether these conditions
evaluate to true of false.

15. PHP can create, open, read, write, delete, and close files on the server.
A. True
B. False
C. PHP can only create, open and close files on the server
D. PHP can read, write and delete files on the server
View Answer
Ans : A

Explanation: PHP can create, open, read, write, delete, and close files on the server.

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

<?php

$x = 8;

$y = 8.0;

echo ($x === $y);

?>

A. 8 === 8
B. No Output
C. 1
D. 0
View Answer
Ans : B

Explanation: === operator returns 1 if $x and $y are equivalent and $x and $y have not the
same type.So it will give no output.
17. The script that executes at the browser side is called _____
A. Client side scripting
B. Server side scripting
C. Both A and B
D. None of the above
View Answer
Ans : A

Explanation: The script that executes at the browser side is called Client-side scripting.

18. PHP can send and receive cookies?


A. True
B. False
C. PHP older version can not send and receive cookies but new version can.
D. PHP new version can not send and receive cookies but old version can.
View Answer
Ans : A

Explanation: PHP can send and receive cookies.

19. On which Platform PHP Runs?


A. Windows
B. Linux
C. Mac OS X
D. All of the above
View Answer
Ans : D

Explanation: PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)

20. The PHP syntax is most similar to:


A. VBScript
B. JavaScript
C. Perl and C
D. All of the above
View Answer
Ans : C

1. Which is the right way of declaring a variable in PHP?

i) $3hello
ii) $_hello
iii) $this
iv) $This

a) Only ii)
b) Only iii)
c) ii), iii) and iv)
d) ii) and iv)
View Answer
Answer:d
Explanation: A variable in PHP can not start with a number, also $this is mainly used to
refer properties of a class so we can’t use $this as a user define variable name.

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

1. <?php
2. $foo = 'Bob';
3. $bar = &$foo;
4. $bar = "My name is $bar";
5. echo $bar;
6. echo $foo;
7. ?>

a)Error
b)My name is BobBob
c)My name is BobMy name is Bob
d)My name is Bob Bob
View Answer
Answer:c
Explanation: Firstly, the line $bar = &$foo; will reference $foo via $bar. So $bar is assigned
value Bob. Therefore $bar = “My name is $bar”; will print My name is Bob($bar=Bob as said
before).
3. Which of the following PHP statements will output Hello World on the screen?

i) echo ("Hello World");


ii) print ("Hello World");
iii) printf ("Hello World");
iv) sprintf ("Hello World");

a)i)andii)
b)i),ii)andiii)
c)i),ii),iii)andiv)
d)i),ii)andiv)
View Answer
Answer:b
Explanation: echo(), print() and printf() all three can be used to output a statement onto the
screen. The sprintf() statement is functionally identical to printf() except that the output is
assigned to a string rather than rendered to the browser.

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

1. <?php
2. $color = "maroon";
3. $var = $color[2];
4. echo "$var";
5. ?>

a)a
b)Error
c)$var
d)r
View Answer
Answer:d
Explanation: PHP treats strings in the same fashion as arrays, allowing for specific
characters to be accessed via array offset notation. In an array, index always starts from 0.
So in the line $var = $color[2]; if we count from start ‘r’ comes at index 2. So the output will
be r.

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

1. <?php
2. $score = 1234;
3. $scoreboard = (array) $score;
4. echo $scoreboard[0];
5. ?>
a) 1
b) Error
c) 1234
d) 2
View Answer
Answer:c
Explanation: The (array) is a cast operator which is used for converting values from other
data types to array.

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

1. <?php
2. $total = "25 students";
3. $more = 10;
4. $total = $total + $more;
5. echo "$total";
6. ?>

a) Error
b) 35 students
c) 35
d) 25 students
View Answer
Answer:c
Explanation: The integer value at the beginning of the original $total string is used in the
calculation. However if it begins with anything but a numerical value, the value will be 0.

7. Which of the below statements is equivalent to $add += $add?


a) $add = $add
b) $add = $add +$add
c) $add = $add + 1
d) $add = $add + $add + 1
View Answer
Answer:b
Explanation: a += b is an addition assignment whose outcome is a = a + b. Same can be
done with subtraction, multiplication, division etc.
8. Which statement will output $x on the screen?
a) echo “\$x”;
b) echo “$$x”;
c) echo “/$x”;
d) echo “$x;”;
View Answer
Answer:a
Explanation: A backslash is used so that the dollar sign is treated as a normal string
character rather than prompt PHP to treat $x as a variable. The backslash used in this
manner is known as escape character.

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

1. <?php
2. function track() {
3. static $count = 0;
4. $count++;
5. echo $count;
6. }
7. track();
8. track();
9. track();
10. ?>

a) 123
b) 111
c) 000
d) 011
View Answer
Answer:a
Explanation: Because $count is static, it retains its previous value each time the function is
executed.

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

1. <?php
2. $a = "clue";
3. $a .= "get";
4. echo "$a";
5. ?>

a) get
b) true
c) false
d) clueget
View Answer
Answer: d
1. What will be the output of the following PHP code?

1. <?php
2. $a = 5;
3. $b = 5;
4. echo ($a === $b);
5. ?>

a) 5 === 5
b) Error
c) 1
d) False
View Answer
Answer:c
Explanation: === operator returns 1 if $a and $b are equivalent and $a and $b have the
same type.

2. Which of the below symbols is a newline character?


a) \r
b) \n
c) /n
d) /r
View Answer
Answer:b
Explanation: PHP treats \n as a newline character.

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

1. <?php
2. $num = 10;
3. echo 'What is her age? \n She is $num years old';
4. ?>

a) What is her age? \n She is $num years old


b)

What is her age?

She is $num years old


c) What is her age? She is 10 years old
d)

What is her age?

She is 10 years old

View Answer
Answer:a
Explanation: When a string is enclosed within single quotes both variables and escape
sequences will not be interpreted when the string is parsed.

4. Which of the conditional statements is/are supported by PHP?

i) if statements

ii) if-else statements

iii) if-elseif statements

iv) switch statements

a) Only i)
b) i), ii) and iv)
c) ii), iii) and iv)
d) i), ii), iii) and iv)
View Answer
Answer:d
Explanation: All are conditional statements supported by PHP as all are used to evaluate
different conditions during a program and take decisions based on whether these conditions
evaluate to true of false.
5. What will be the output of the following PHP code?

1. <?php
2. $team = "arsenal";
3. switch ($team) {
4. case "manu":
5. echo "I love man u";
6. case "arsenal":
7. echo "I love arsenal";
8. case "manc":
9. echo "I love manc"; }
10. ?>

a)I love arsenal


b)Error
c)I love arsenalI love manc
d)I love arsenalI love mancI love manu
View Answer
Answer:c
Explanation: If a break statement isn’t present, all subsequent case blocks will execute until
a break statement is located.

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

i) for loop

ii) while loop

iii) do-while loop

iv) foreach loop

a)i)andii)
b)i),ii)andiii)
c)i),ii),iii)andiv)
d)Onlyiv)
View Answer
Answer:c
Explanation: All are supported looping statements in PHP as they can repeat the same
block of code a given number of times, or until a certain condition is met.
7. What will be the output of the following PHP code?

1. <?php
2. $user = array("Ashley", "Bale", "Shrek", "Blank");
3. for ($x=0; $x < count($user); $x++) {
4. if ($user[$x] == "Shrek") continue;
5. printf ($user[$x]);
6. }
7. ?>

a) AshleyBale
b) AshleyBaleBlank
c) ShrekBlank
d) Shrek
View Answer
Answer:b
Explanation: The continue statement causes execution of the current loop iteration to end
and commence at the beginning of the next iteration.

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


a)12
b)1
c)Error
d)5
View Answer
Answer:d
Explanation: ?: is known as ternary operator. If condition is true then the part just after the ?
is executed else the part after : .

9. What will be the value of $a and $b after the function call in the following PHP code?

1. <?php
2. function doSomething( &$arg ) {
3. $return = $arg;
4. $arg += 1;
5. return $return;
6. }
7. $a = 3;
8. $b = doSomething( $a );
9. ?>

a) a is 3 and b is 4
b) a is 4 and b is 3
c) Both are 3
d) Both are 4
Answer:b
10. Who is the father of PHP?
a) Rasmus Lerdorf
b) Willam Makepiece
c) Drek Kolkevi
d) List Barely
View Answer
Answer: a

CONSTANT

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

1. <?php
2. define("GREETING", "PHP is a scripting language", true);
3. echo GREETING;
4. echo "<br>"
5. echo GREETING;
6. ?>

a) PHP is a scripting language


b)

GREETING

GREEtING

c) GREETING
d)

PHP is a scripting language

PHP is a scripting language

View Answer
Answer:d
Explanation: Since the third parameter is true in define(“GREETING”, “PHP is a scripting
language”, true) is true GREETING becomes case insensitive.
2. What will be the output of the following PHP code?

1. <?php
2. define("GREETING", "PHP is a scripting language");
3. echo $GREETING;
4. ?>

a) $GREETING
b) no output
c) PHP is a scripting language
d) GREETING
View Answer
Answer:b
Explanation: Constants do not need a $ before them, they are referenced by their variable
names itself.

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


1. <?php
2. define('GREETING_TEST', 'PHP is a scripting language', true);
3. echo GREETING_TESt;
4. $changing_variable = 'test';
5. echo constant('GREETING_' . strtoupper($changing_variable));
6. ?>

a)

PHP is a scripting language

PHP is a scripting language

b) GREETING_TESt
c) PHP is a scripting language
d)

PHP is a scripting language

GREETING_TEST

View Answer
Answer:a
Explanation: echo constant(x) output x, and x here is the concatenation of GREETING_ and
$changing variable with. operator.
4. What will be the output of the following PHP code?

1. <?php
2. class Constants
3. {
4. define('MIN_VALUE', '0.0');
5. define('MAX_VALUE', '1.0');
6. public static function getMinValue()
7. {
8. return self::MIN_VALUE;
9. }
10. public static function getMaxValue()
11. {
12. return self::MAX_VALUE;
13. }
14. }
15. echo Constants::getMinValue();
16. echo Constants::getMaxValue();
17. ?>

a) 0.01.0
b) 01
c) No output
d) ERROR
View Answer
Answer:d
Explanation: In a class constants should be defined const MIN_VALUE = 0.0;const
MAX_VALUE = 1.0; instead.

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

1. <?php
2. define("__LINE__", "PHP is a scripting language");
3. echo __LINE__;
4. ?>

a) PHP is a scripting language


b) __LINE__
c) 2
d) ERROR
View Answer
Answer:c
Explanation: __LINE__ is a magical constant that gives the current line number and cannot
be used a variable/constant name.
6. What will be the output of the following PHP code?

1. <?php
2. define('IF', 42);
3. echo "IF: ", IF;
4. ?>

a) IF:42
b) No output
c) IF:
d) ERROR
View Answer
Answer:d
Explanation: Keyword like IF cannot be used as constant names.

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

1. <?php
2. define("NEW_GOOD_NAME_CONSTANT", "I have a value");
3. define("OLD_BAD_NAME_CONSTANT", NEW_GOOD_NAME_CONSTANT);
4.
5. echo NEW_GOOD_NAME_CONSTANT;
6. echo OLD_BAD_NAME_CONSTANT;
7. ?>

a) I have a value
b) I have a valueI have a value
c) ERROR
d) I have a valueNEW_GOO_NAME_CONSTANTS
View Answer
Answer:b
Explanation: Constants can be set as values for other constants.

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

1. <?php
2. define('GOOD_OCTAL', 0700);
3. define('BAD_OCTAL', 0600);
4. print GOOD_OCTAL;
5. print '<br>';
6. print BAD_OCTAL;
7. ?>

a)

448
384

b)

0700

0800

c) ERROR
d) No output
View Answer
Answer:a
Explanation: Anything starting from 0 is evaluated as an octal.

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

1. <?php
2. define("VAR_NAME","test");
3. ${VAR_NAME} = "value";
4. echo VAR_NAME;
5. echo ${VAR_NAME};
6. ?>

a) test
b) testtest
c) testvalue
d) error, constant value cannot be changed
View Answer
Answer:c
Explanation: ${VAR_NAME} creates a new variable which is not same as VAR_NAME.

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

1. <?php
2. class myObject { }
3. define('myObject::CONSTANT', 'test');
4. echo myObject::CONSTANT;
5. ?>

a) test
b) error
c) myObject::CONSTANT
d) no output
View Answer
Answer: b
PRINT AND ECHO:
1. How many ways user can print output in PHP?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : B

Explanation: there are two basic ways to get output in PHP:-echo, print.

2. print statement can take _____ argument?


A. 1
B. 2
C. 3
D. 4
View Answer
Ans : A

Explanation: print can take one argument.

3. How many return value does echo statement has?


A. 1
B. 2
C. 3
D. 0
View Answer
Ans : D

Explanation: echo has no return value

4. Echo statement is written under parentheses?


A. True
B. False
C. Only for string it written under parentheses
D. Only for variable it written under parentheses
View Answer
Ans : B

Explanation: Echo statement does not written under parentheses.

5. Which statement is faster amoung echo and print?


A. echo
B. print
C. echo and print has same speed
D. None of the above
View Answer
Ans : A

Explanation: Echo is faster than print.

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

<?php

echo "Hello world </br> I am learning PHP at letsfindcourse";

?>

A. Hello world
B. Hello world I am learning PHP at letsfindcourse
C. Hello world
I am learning PHP at letsfindcourse
D. Error
View Answer
Ans : C

Explanation: The break tag is used as break line.

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

<?php

$five = 5;
print($five);

print $five;

?>

A. 05
B. 55
C. 50
D. Error
View Answer
Ans : B

Explanation: Print can be used with or without parentheses.

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

<?php

$a = "Hello";

$b = "World";

echo "$a"+"$b";

?>

A. HelloWorld
B. Hello+World
C. 0
D. Error
View Answer
Ans : C

Explanation: In an echo statement, you can not use plus sign to join two strings.

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

<?php

$a = "hello";

$b = "world";

print($a$b);
?>

A. helloworld
B. hello
C. Nothing
D. error
View Answer
Ans : D

Explanation: The above syntax will produce an error, unlike the echo statement.

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

<?php

print("I"."am"."learning"."php");

?>

A. Iamlearningphp
B. I am learning php
C. Nothing
D. error
View Answer
Ans : A

11. which of the following is correct echo statement?


A. echo "<h2>PHP is Fun!</h2>";
B. echo "PHP is Fun!<br>";
C. echo "PHP ", "is ", "Fun!";
D. All of the above
View Answer
Ans : D

Explanation: All echo statement is correct.

12. which of the following is correct print statement?


A. print "<h2>PHP is Fun!</h2>";
B. print "PHP is Fun!<br>";
C. print "PHP ", "is ", "Fun!";
D. All of the above
View Answer
Ans : D

Explanation: All print statement is correct.

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

<?php

echo "This is <i>Letsfindcourse</i>";

?>

A. This is Letsfindcourse
B. This is Letsfindcourse(Letsfindcourse in italic)
C. This is
D. Error
View Answer
Ans : B

Explanation: the output of the following PHP code This is India(India in italic)

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

<?php

$arr = array('0' => "Letsfindcourse",

'1' => "Computer",

'2' => "Science",

'3' => "Portal");

print_r($arr[-1]);

?>
A. Portal
B. Letsfindcourse
C. Error
D. No Output
View Answer
Ans : C

Explanation: the output of the following PHP code is Undefined index -1.

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

<?php

$arr = array('0' => "Letsfindcourse",

'1' => "Computer",

'2' => "Science",

'3' => "Portal");

print_r($arr[0]);

?>

A. Portal
B. Letsfindcourse
C. Error
D. No Output
View Answer
Ans : B

Explanation: the output of the following PHP code is Letsfindcourse.

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

<?php

echo 'This is "letsfindcourse"' ;

?>
A. This is letsfindcourse
B. This is "letsfindcourse"
C. Error
D. No Output
View Answer
Ans : B

Explanation: the output of the following PHP code This is "letsfindcourse".

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

<?php

echo "This is "echo statement" ";

?>

A. This is "echo statement"


B. echo statement
C. Error
D. No Output
View Answer
Ans : C

Explanation: the output of the following PHP code Syntax Error, unexpected echo
statement.

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

<?php

echo "This","is"|"a","PHP"."MCQs";

?>

A. ThisisaPHPMCQs
B. ThisisPHPMCQs
C. Thisis a PHPMCQs
D. Thisis aPHPMCQS
View Answer
Ans : B
Explanation: You can use only comma and dot operator to join strings, other characters do
not have the same function.

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

<?php

echo "This","is"&"a","PHP"."MCQs";

?>

A. ThisisaPHPMCQs
B. Thisis PHPMCQs
C. This aPHPMCQS
D. ThisaPHPMCQs
View Answer
Ans : D

Explanation: The output for the following PHP code is ThisaPHPMCQs.

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

<?php

echo "This","is"@"a","PHP"."MCQs";

?>

A. Thisis@aPHPMCQs
B. ThisaPHPMCQs
C. No Output
D. Error
View Answer
Ans : D
VARIABLE:
1. Any variables declared in PHP must begin with a _____?
A. .
B. #
C. &
D. $
View Answer
Ans : D

Explanation: Any variables declared in PHP must begin with a dollar sign ($)

2. A variable can have ________?


A. long descriptive names
B. short names
C. Both A and B
D. None of the above
View Answer
Ans : C

Explanation: A variable can have long descriptive names (like $factorial, $even_nos) or
short names (like $n or $f or $x)

3. A variable name can only contain ____________?


A. alphanumeric characters
B. underscores
C. Both A and B
D. None of the above
View Answer
Ans : C

Explanation: A variable name can only contain alphanumeric characters and underscores in
their name.

4. Variable names in PHP must start with ?


A. letter
B. underscore
C. no numbers
D. All of the above
View Answer
Ans : D

Explanation: One must keep in mind that variable names in PHP must start with a letter or
underscore and should not start with numbers.

5. PHP variables are case-sensitive?


A. True
B. False
C. For "sum" variable it is case-sensitive
D. None of the above
View Answer
Ans : A

Explanation: PHP variables are case-sensitive, i.e., $lfc and $LFC are treated differently.

6. How many variable scope are there in php?


A. 2
B. 3
C. 1
D. 4
View Answer
Ans : B

Explanation: Depending on the scopes, PHP has three variable scopes: Local, Global and
static variable scope.

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

<?php

$x = 1;

$y = 2;
$z = "$x + $y";

echo "$z";

?<

A. $x + $y
B. 3
C. 1+2
D. 12
View Answer
Ans : C

Explanation: Variable z will store 1 + 2 because 1 + 2 is given in double-quotes.

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

<?php

$x = 3.3;

$y = 2;

echo $x % $y;

?>

A. 1.3
B. 1
C. 0
D. Error
View Answer
Ans : B

Explanation: % is the modulo operator. Unlike in C, we can use it to get a reminder or


floating-point numbers in PHP.

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

<?php

$a = 1;
$b = 2;

$c = 3;

echo ($a % ($b) + $c);

?>

A. 2
B. 3
C. 4
D. 5
View Answer
Ans : A

Explanation: The innermost bracket is evaluated first, since it covers only variable b it is as
good as not using brackets.

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

<?php

$a = 1;

$b = 2;

$c = 3;

echo ($a * (($b) - $c));

?>

A. 1
B. -1
C. 2
D. -2
View Answer
Ans : B
1. What will be the output of the following PHP code?

1. <?php
2. $x = 5;
3. $y = 10;
4. $z = "$x + $y";
5. echo "$z";
6. ?>

a) 15
b) 10 + 5
c) $z
d) $x + $y
View Answer
Answer:b
Explanation: Variable z will store 10 + 5 because 10 + 5 is given in double-quotes.

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

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

a) 4 = 4 + 3 + 1
b) 8
c) 8 = 4 + 3 +1
d) Error
View Answer
Answer:a
Explanation: Again since the variables are inside double quotes we get this result.

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

1. <?php
2. $x = 4;
3. $y = 3
4. $z = 1;
5. $z = $z + $x + $y;
6. echo "$z";
7. ?>

a) $z
b) 15
c) 8
d) 1
View Answer
Answer:c
Explanation: Normal addition of variables x, y and z occurs and result of 8 will be displayed.

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

1. <?php
2. $x = 3.3;
3. $y = 2;
4. echo $x % $y;
5. ?>

a) 0
b) 1
c) 2
d) Error
View Answer
Answer:b
Explanation: % is the modulo operator. Unlike in C we can use it get reminder or floating
point numbers in PHP.

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

1. <?php
2. $x = 10;
3. $y = 4;
4. $z = 3;
5. echo $x % $y % $z;
6. ?>

a) 0
b) 1
c) 2
d) Error
View Answer
Answer:c
Explanation: The expression is considered as ($x%$y)%z in this case (10%4)%3 which is 2.
6. What will be the output of the following PHP code?

1. <?php
2. $x = 10;
3. $y = 4;
4. $z = 3;
5. echo ($x % ($y) + $z);
6. ?>

a) 5
b) 3
c) 0
d) 1
View Answer
Answer:a
Explanation: The innermost bracket is evaluated first, since it covers only variable y it is as
good as not using brackets.

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

1. <?php
2. $x = 30;
3. $y = 20;
4. $z = 10;
5. echo $x + $y - $z / ($z - $y);
6. ?>

a) 41
b) -4
c) -5
d) 51
View Answer
Answer:d
Explanation: First ($z – $y) is evaluated then -$z/($z – $y) is evaluated this results in 1
which is added to $x + $y therefore we get 51.

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

1. <?php
2. $x = -1;
3. $y = 1;
4. $z = $x * $y + $z;
5. echo $z;
6. ?>
a) Undefined variable z
b) -1
c)

Undefined variable z

-1

d) None of the mentioned


View Answer
Answer:c
Explanation: Since the variable z is not defined it returns the error also it takes z as 0 and
returns the value -1.

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

1. <?php
2. $x = 4;
3. $y = -3;
4. $z = 11;
5. echo 4 + $y * $z / $x;
6. ?>

a) 4.25
b) 3.25
c) -3.25
d) -4.25
Answer:d
Explanation: First the * is evaluated then / followed by + therefore we can rewrite this
expression as 4 +((- 3 * 11) / 4) which results in -4.25.
10. What will be the output of the following PHP code?

1. <?php
2. $x = 3.5;
3. $y = 2;
4. $z = 2;
5. echo $x / $y / $z;
6. ?>

a) 1.75
b) 0.875
c) 3.5
d) Error
View Answer
Answer: b

DATATYPE:
1. How many different data types are available in php?
A. 6
B. 7
C. 8
D. 9
View Answer
Ans : C

Explanation: PHP allows eight different data types.

2. How many compound data types are available in php?


A. 1
B. 2
C. 3
D. 4
View Answer
Ans : C

Explanation: The first five are called simple data types and the last three are compound
data types.

3. Which one is not a data type in PHP?


A. Resources
B. Objects
C. Null
D. Void
View Answer
Ans : D

Explanation: The void is not a data type in PHP.

4. The range of integers must lie between ___________?


A. -2^15 to 2^15.
B. -2^16 to 2^16.
C. -2^31 to 2^31.
D. -2^32 to 2^32.
View Answer
Ans : C

Explanation: The range of integers must lie between -2^31 to 2^31.

5. How many value does Boolean data type hold?


A. 1
B. 2
C. 3
D. 4
View Answer
Ans : B

Explanation: Boolean: Hold only two values, either TRUE or FALSE.

6. Objects are defined as instances of user defined classes that can hold
____________?
A. values
B. functions
C. both values and functions
D. None of the above
View Answer
Ans : C

Explanation: Objects are defined as instances of user-defined classes that can hold both
values and functions.

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

<?php

if(TRUE)

echo "This condition is TRUE";

if(FALSE)

echo "This condition is not TRUE";

?>

A. This condition is TRUE


B. This condition is not TRUE
C. No Output
D. Error
View Answer
Ans : A

Explanation: This condition is TRUE is the output of the following PHP code.

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

<?php

$lfc = NULL;

echo $lfc;

?>

A. 0
B. Null
C. No Output
D. Error
View Answer
Ans : C

Explanation: The output of the following PHP code is no output.

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

<?php

$x1 = 10.58;

$x2 = 21.18;

$sum = $x1 + $x2;

echo $sum;

?>

A. 31
B. 32
C. 31.00
D. 31.76
View Answer
Ans : D

Explanation: 31.76 is the output of the following code.

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

<?php

$intArray = array( 10, 20 , 30);

echo "First Element: $intArray[3]


";

?>

A. First Element: 10
B. First Element: 20
C. First Element: 30
D. First Element:
View Answer
Ans : D
PHP and MY SQL
MODULE – 1(BASIC)
1. What does PHP stand for?

i) Personal Home Page

ii) Hypertext Preprocessor

iii) Pretext Hypertext Processor

iv) Preprocessor Home Page

a)Both(i)and(iii)
b)Both(ii)and(iv)
c)Only(ii)
d)Both(i)and(ii)

Answer:d
Explanation: PHP previously stood for Personal Home Page now stands for Hypertext
Preprocessor.

2.PHP files have a default file extension of_______


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

Answer:.php
Explanation: To run a php file on the server, it should be saved as AnyName.php

3.What should be the correct syntax to write a PHP code?


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

Answer:c
Explanation: Every section of PHP code starts and ends by turning on and off PHP tags
to let the server know that it needs to execute the PHP in between them.

4. Which of the following is/are a PHP code editor?

i) Notepad

ii) Notepad++

iii) Adobe Dreamweaver


iv) PDT

a)Only(iv)
b)(i),(ii),(iii)and(iv)
c)(i),(ii)and(iii)
d)Only(iii)

Answer:b
Explanation: Any of the above editors can be used to type php code and run it.

5. Which of the following must be installed on your computer so as to run PHP


script?

i) Adobe Dreamweaver

ii) XAMPP

iii) Apache and PHP

iv) IIS

a)(i),(ii),(iii)and(iv)
b)Only(ii)
c)(ii)and(iii)
d)(ii),(iii)and(iv)

Answer:d
Explanation: To run PHP code you need to have PHP and a web server, both IIS and
Apache are web servers. You can choose either one according to your platform.

6.Which version of PHP introduced Try/catch Exception?


a)PHP4
b)PHP5
c)PHP6
d)PHP5andlate

Answer:d
Explanation: PHP 5 version and later versions added support for Exception Handling.

7. How should we add a single line comment in our PHP code?

i) /?

ii) //

iii) #
iv) /* */

a)Only(ii)
b)(i),(iii)and(iv)
c)(ii),(iii)and(iv)
d)Both(ii)and(iv)

Answer:c
Explanation: /* */ can also be use to comment just a single line although it is used for
paragraphs. // and # are used only for single line comment.

8. Which of the following PHP statement/statements will store 111 in variable num?

i) int $num = 111;


ii) int mum = 111;
iii) $num = 111;
iv) 111 = $num;

a)Both(i)and(ii)
b)(i),(ii),(iii)and(iv)
c)Only(iii)
d)Only(i)

Answer:c
Explanation: You need not specify the datatype in php.

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

1. <?php
2. $num = 1;
3. $num1 = 2;
4. print $num . "+". $num1;
5. ?>

a)3
b)1+2
c)1.+.2
d)Error

Answer:b
Explanation: .(dot) is used to combine two parts of the statement. Example ($num . “Hello
World”) will output 1Hello World.

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

1. <?php
2. $num = "1"
3. $num1 = "2";
4. print $num+$num1;
5. ?>
a)3
b)1+2
c)Error
d)12

Answer:a
Explanation: The numbers inside the double quotes are considered as integers and
not string, therefore the value 3 is printed and not 1+2.

11. Which is the right way of declaring a variable in PHP?

i) $3hello
ii) $_hello
iii) $this
iv) $This

a)Only(ii)
b)Only(iii)
c)(ii),(iii)and(iv)
d)(ii)and(iv)

Answer:d
Explanation: A variable in PHP can not start with a number, also $this is mainly used to
refer properties of a class so we can’t use $this as a user define variable name.

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

1. <?php
2. $foo = 'Bob';
3. $bar = &$foo;
4. $bar = "My name is $bar";
5. echo $bar;
6. echo $foo;
7. ?>

a)Error
b) My name is BobBob
c)My name is BobMy name is Bob
d)My name is Bob Bob

Answer:c
Explanation: Firstly, the line $bar = &$foo; will reference $foo via $bar. So $bar is assigned
value Bob. Therefore $bar = “My name is $bar”; will print My name is Bob($bar=Bob as
said before).

13. Which of the following PHP statements will output Hello World on the screen?

i) echo ("Hello World");


ii) print ("Hello World");
iii) printf ("Hello World");
iv) sprintf ("Hello World");
a)(i)and(ii)
b)(i),(ii)and(iii)
c)(i),(ii),(iii)and(iv)
d)(i),(ii)and(iv)

Answer:b
Explanation: echo(), print() and printf() all three can be used to output a statement onto
the screen. The sprintf() statement is functionally identical to printf() except that the output
is assigned to a string rather than rendered to the browser.

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

1. <?php
2. $color = "maroon";
3. $var = $color[2];
4. echo "$var";
5. ?>

a)a
b)Error
c)$var
d)r

Answer:d
Explanation: PHP treats strings in the same fashion as arrays, allowing for specific
characters to be accessed via array offset notation. In an array, index always starts from
0. So in the line $var = $color[2]; if we count from start ‘r’ comes at index 2.so the output
will be r.

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

1. <?php
2. $score = 1234;
3. $scoreboard = (array) $score;
4. echo $scoreboard[0];
5. ?>

a)1
b)Error
c)1234
d)2

Answer:c
Explanation: The (array) is a cast operator which is used for converting values from other
data types to array.

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

1. <?php
2. $total = "25 students";
3. $more = 10;
4. $total = $total + $more;
5. echo "$total";
6. ?>
a)Error
b)35students
c)35
d)25 students

Answer:c
Explanation: The integer value at the beginning of the original $total string is used in the
calculation. However if it begins with anything but a numerical value, the value will be 0.

17.Which of the below statements is equivalent to $add += $add?


a)$add=$add
b)$add=$add+$add
c)$add=$add+1
d)$add=$add+$add+1

Answer:b
Explanation: a += b is an addition assignment whose outcome is a = a + b. Same can be
done with subtraction, multiplication, division etc.

18.Which statement will output $x on the screen?


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

Answer:a
Explanation: A backslash is used so that the dollar sign is treated as a normal string
character rather than prompt PHP to treat $x as a variable. The backslash used in this
manner is known as escape character.

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

1. <?php
2. function track() {
3. static $count = 0;
4. $count++;
5. echo $count;
6. }
7. track();
8. track();
9. track();
10. ?>

a)123
b)111
c)000
d)011

Answer:a
Explanation: Because $count is static, it retains its previous value each time the function
is executed.
20. What will be the output of the following PHP code?

1. <?php
2. $a = "clue";
3. $a .= "get";
4. echo "$a";
5. ?>

a)get
b)true
c)false
d)clueget

Answer:d
Explanation: ‘.’ is a concatenation operator. $a. = “get” is same as $a=$a.”get” where $a
is having value of “clue” in the previous statement. So the output will be clueget.

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

1. <?php
2. $a = 5;
3. $b = 5;
4. echo ($a === $b);
5. ?>

a)5===5
b)Error
c)1
d)False

Answer:c
Explanation: === operator returns 1 if $a and $b are equivalent and $a and $b have the
same type.

22. Which of the below symbols is a newline character?


a)\r
b)\n
c)/n
d)/r

Answer:b
Explanation: PHP treats \n as a newline character.

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

1. <?php
2. $num = 10;
3. echo 'What is her age? \n She is $num years old';
4. ?>

a) What is her age? \n She is $num years old


b)What is her age?
She is $num years old

c) What is her age? She is 10 years old


d)What is her age?

She is 10 years old

Answer:a
Explanation: When a string is enclosed within single quotes both variables and escape
sequences will not be interpreted when the string is parsed.

24. Which of the conditional statements is/are supported by PHP?


i) if statements

ii) if-else statements

iii) if-elseif statements

iv) switch statements

a)Only(i)
b)(i),(ii)and(iv)
c)(ii),(iii)and(iv)
d)(i),(ii),(iii)and(iv)

Answer:d
Explanation: All are conditional statements supported by PHP as all are used to evaluate
different conditions during a program and take decisions based on whether these
conditions evaluate to true of false.

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

1. <?php
2. $team = "arsenal";
3. switch ($team) {
4. case "manu":
5. echo "I love man u";
6. case "arsenal":
7. echo "I love arsenal";
8. case "manc":
9. echo "I love manc"; }
10. ?>

a)I love arsenal


b)Error
c)I love arsenalI love manc
d)I love arsenalI love mancI love manu

Answer:c
Explanation: If a break statement isn’t present, all subsequent case blocks will execute
until a break statement is located.
26. Which of the looping statements is/are supported by PHP?

i) for loop

ii) while loop

iii) do-while loop

iv) foreach loop

a)(i)and(ii)
b)(i),(ii)and(iii)
c)(i),(ii),(iii)and(iv)
d)Only(iv)

Answer:c
Explanation: All are supported looping statements in PHP as they can repeat the same
block of code a given number of times, or until a certain condition is met.

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

1. <?php
2. $user = array("Ashley", "Bale", "Shrek", "Blank");
3. for ($x=0; $x < count($user); $x++) {
4. if ($user[$x] == "Shrek") continue;
5. printf ($user[$x]);
6. }
7. ?>

a)AshleyBale
b)AshleyBaleBlank
c)ShrekBlank
d)Shrek

Answer:b
Explanation: The continue statement causes execution of the current loop iteration to end
and commence at the beginning of the next iteration.

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


a)12
b)1
c)Error
d)5

Answer:d
Explanation: ?: is known as ternary operator. If condition is true then the part just after the
? is executed else the part after : .
29. What will be the value of $a and $b after the function call in the following PHP
code?

1. <?php
2. function doSomething( &$arg ) {
3. $return = $arg;
4. $arg += 1;
5. return $return;
6. }
7. $a = 3;
8. $b = doSomething( $a );
9. ?>

a)a is 3 and b is 4
b)a is 4 and b is 3
c)Both are 3
d)Both are 4

Answer:b
Explanation: $a is 4 and $b is 3. The former because $arg is passed by reference, the
latter because the return value of the function is a copy of the initial value of the argument.

30. Who is the father of PHP?


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

Answer:a
Explanation: PHP was originally created by Rasmus Lerdorf in 1994.

31. What is the data type of $TV in this Line 1?

<php

$tax=10.3;

$TV="10.3+$TV"; # Line 1

?>

A. Integer
B. String
C. Unknown
D. No Output

Answer: B

Explanation: The string is the data type of $TV in this Line 1


32. What is the data type of $TV in the above code?
<php
$TV;

echo gettype($TV);

?>

A. Integer
B. String
C. Unknown
D. Null
Answer : D

Explanation: NULL is the data type of $TV in the above code

33. How doaes the identity operator === compare two values?

A.It converts them to a common compatible data type and then compares the
resulting values

B. It returns True only if they are both of the same type and value

C. If the two values are strings, it performs a lexical comparison

D. It bases its comparison on the C strcmp function exclusively

E. It converts both values to strings and compares the

Answer: A

34. Under what circumstance is it impossible to assign a default value to a


parameter while declaring a function?

A. When the parameter is Boolean

B. When the function is being declared as a member of a class

C. When the parameter is being declared as passed by reference

D. When the function contains only one parameter

E. Never
Answer: C

35.Variables always start with a ........ in PHP

A.Pond-sign

B.Yen-sign

C.Dollar-sign

D.Euro-sign

Answer: C

36.PHP is an open source software.

A.True

B.False

Answer: A

37.Which of the following is not valid PHP code?

A. $_10

B . ${“MyVar”}

C. &$something

D .$10_somethings

E. $aVaR

Answer: C

38.PHP runs on different platforms (Windows, Linux, Unix, etc.)

A.True

B.False
Answer: A

39.You can test the type of any variable with the ..... function.

A. whattype()

B.showtype()

C. gettype()

D.settype()

Answer: C

40.String values must be enclosed in ......

A.single quotes

B.double quotes

C.both A and B

D.none of above

Answer: C

Das könnte Ihnen auch gefallen