PHP Whole PDF
PHP Whole PDF
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
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
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
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
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
View Answer
Answer: a
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
View Answer
Answer: d
View Answer
Answer: d
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
View Answer
Answer: c
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
B. Characters
C. Timestamp
D. None of them
View Answer
Answer: c
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.
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.
20 | P a g e
75. Which of the following are types of PHP authentication implementation methodologies?
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
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.
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.
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.
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.
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
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.
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.
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
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.
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.
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.
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
A. commit()
B. undo()
C. back()
D. rollback()
View Answer
Answer: D
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?
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
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.
?>
1. Which two predefined variables are used to retrieve information from forms?
Answer : B
2. The attack which involves the insertion of malicious code into a page frequented by other users is
known as..
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
A. FILTER_VALIDATE_EMAIL
B. FILTER_VALIDATE_MAIL
C. VALIDATE_EMAIL
D. VALIDATE_MAIL
Answer : A
A. 5
B. 6
C. 7
D. 8
Answer : C
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?
ANSWER: Option B
2. The attack which involves the insertion of malicious code into a page frequented by other users is known
as..
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
A. FILTER_VALIDATE_EMAIL
B. FILTER_VALIDATE_MAIL
C. VALIDATE_EMAIL
D. VALIDATE_MAIL
Answer: Option A
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
ANSWER: OPTION D
Explanation: All the above three statements hold true for forms in HTML.
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.
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.
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
ANSWER: OPTION C
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?
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?
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?
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
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
ANSWER: OPTION B
ANSWER: OPTION C
Ans : D
Explanation: All the above three statements hold true for forms in HTML.
A. text box.
B. radio button.
C. submit button.
D. All of these.
70 | P a g e
Ans : D
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.
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
Ans : C
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?
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?
Ans : B
Explanation: The use of POST method for form submission does not allow to bookmark the
page.
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?
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”.
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.
76 | P a g e
Answer: b
Explanation: The default value of the max_input_time directive is 60 seconds.
Answer: c
Explanation: The max_file_limit directive sets an upper limit on the number of files which can
be simultaneously uploaded.
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.
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.
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).
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
A. setcookie ( ) function
B. set ( ) function
C. cookie_set ( ) function
D. None of them
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
A. In integer form
B. In string form
C. In boolean form
D. None of them
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
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()
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
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
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
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
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']);
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
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
Ans:d
Ans:a
Session(PHP)
1.Which one of the following is the very first task executed by a session enabled page?
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.
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).
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.
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
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
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.
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.
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.
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.
A) True
B) False
Answer:-A
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
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 ( )
a.setcookie ( ) function
b.set ( ) function
c.cookie_set ( ) function
d.None of them
b.CGI servers
c.ISS servers
d.PWS servers
28.What kind of session will maintain its identity as long as user stays within a site?
c.Session
d.None of them
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
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 ( )
a.setcookie ( )
b.set_header ( )
c.header ( )
d.All of them
Answer: (b).set_header ( )
a.GET argument
b.POST argument
c.HEADER arguments
d.Both a and b
a.PHP2.1
b.PHP3
c.PHP4.1
d.PHP6
Answer: (c).PHP4.1
a.Session is started
c.Session is terminated
d.None of them
38.Session_unset ( ) takes
a.1 argument
b.2 arguments
c.3 arguments
d.No argument
Answer: (b).Stateless
d.All of them
d.None of them
a.Superglobal array
b.$_COOKIE
c.Global function
d.Both a and b
a.info ( ) function
b.ini_file ( ) function
c.phpinfo ( ) function
d.php_ini ( ) function
44.Which two predefined variables are used to retrieve information from forms?
a.$GET & $SET
45.The attack which involves the insertion of malicious code into a page frequented by other users is
known as..
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
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>!
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
a.1
b.2
c.3
d.4
Answer: (b).2
i) $_SERVER[‘PHP_AUTH_USER’].
ii) $_SERVER[‘PHP_AUTH_USERS’].
iii) $_SERVER[‘PHP_AUTH_PU’].
iv) $_SERVER[‘PHP_AUTH_PW’].
i) header()
ii) footer()
iii) inset()
iv) isset()
b.footer()
c.inset()
d.isset()
Answer: (d).isset()
58.In which authentication method does changing the username or password can be done only by
entering the code and making the manual adjustment.
b.File-based authentication
c.Data-based authentication
59.The authenticationFile.txt, the file which stores username and password should be stored _ the
server document root.
a.Inside
b.Outside
c.Within
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?
Answer: (a).
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
Answer: (d).
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?
Answer: (b).
65.Which one of the following statements should be used to disable the use of two classes administrator
and janitor?
Answer: (a).
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
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()
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']);
d. Error
Answer: (c).
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
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
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
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.
A. fun
B. def
C. function
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.
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";
}
?>
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
<?php
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.
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
A. True
B. False
C. Only Built-In function
D. Only User-defined function
Ans : B
return $a + $b;
?>
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.
<?php
}
setHeight(350);
?>
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?
Ans : C
Explanation: $x=TRUE; echo empty($x); of the following cases would function empty()
return FALSE.
<?php
function WRITEMSG() {
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
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.
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()
Answer: A
C set()
Answer: B
B empty()
C determine()
Answer: B
21. Which one of the following is the right way of defining a function in PHP?
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
● 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
< ?php
function a()
function b()
a();
a();
?>
● A. I am b
● B. I am bI am a
● C. Error
● D. I am a Error
Answer: Option D
Explanation:
< ?php
function a()
function b()
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.
< ?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: 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
● View Answer
● Workspace
● Report
● Discuss
< ?php
function foo($msg)
echo "$msg";
$var1 = "foo";
?>
● A. Error.
● B. $msg
● C. 0
Answer: Option D
Explanation:
It is possible to call a function using a variable which stores the function name.
< ?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
● In a function call
● In execution time
● In deceleration time
● None of them
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
a. echo()
b. isset()
c. print()
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()
Ans: c
● None of them
Answer: A
Answer: c
● X is passed by value
● X is passed by reference
● 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.
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.
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.
< ?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
A. orangebanana
B. appleorange
C. orangeorange
D. appleapple
Answer : A
A. True
B. 1
C. False
D. 2
Answer : D
A. array_unshift()
B. into_array()
C. inend_array()
D. array_push()
Answer : D
A. this_array()
B. is_array()
C. do_array()
D. in_array()
Answer :B
A. 3
B. 4
C. 5
D. 6
Answer : D
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
Answer : D
A. Error
B. Array ( [0] => apple [1] => mango [2] => peach )
C. Array ( [0] => apple [1] => mango )
D. Array ( [0] => pear [1] => orange )
Answer : C
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
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?
Answer : D
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
A. zip_compress()
B. zip()
C. compress()
D. gzcompress()
Answer : D
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
A. Hello World
B. Hello
World
C. Hello world
D. World
Answer : B
A. welcome to India
B. welcome to india
C. Welcome to India
D. Welcome to india
Answer : A
A. Call By Value
B. Call By Reference
C. Default Argument Value
D. Type Hinting
Answer : A
A. Error
B. 0
C. 42
D. 84
Answer : C
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
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
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: Option C
Explanation:
Like many programming languages, the first element of an array has an index value of 0.
A. sort()
B. asort()
C. rsort()
D. dsort()
View Answer
Workspace
Report
Discuss
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.
View Answer
Workspace
Report
Discuss
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.
A. mango
B. Error
C. peach
D. 0
View Answer
Workspace
Report
Discuss
Answer: Option B
A. karnataka 11,35,000
B. 11,35,000
C. population 11,35,000
D. karnataka population
View Answer
Workspace
Report
Discuss
Answer: Option B
Explanation:
Treat states as a multidimensional array and accordingly traverse it to get the value.
A. this_array()
B. is_array()
C. do_array()
D. in_array()
View Answer
Workspace
Report
Discuss
Answer: Option B
Explanation:
A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean
is_array(mixed variable).
A. array_unshift()
B. into_array()
C. inend_array()
D. array_push()
View Answer
Workspace
Report
Discuss
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.
A. True
B. 1
C. False
D. 2
View Answer
Workspace
Report
Discuss
Answer: Option D
Explanation:
The array_search() function searches an array for a specified value, returning its key if located
and FALSE otherwise.
A. orangebanana
B. appleorange
C. orangeorange
D. appleapple
View Answer
Workspace
Report
Discuss
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: Option C
Explanation:
prev()
View Answer
Workspace
Report
Discuss
Answer: Option D
Explanation:
The array entity holding pear and mango is counted as an item, just as its contents are.
A. count()
B. array_count()
C. array_count_values()
D. count_values()
View Answer
Workspace
Report
Discuss
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: Option C
Explanation:
natcasesort()
View Answer
Workspace
Report
Discuss
Answer: Option D
Explanation:
The array_slice() function returns a section of an array based on a starting and ending offset
value.
View Answer
Workspace
Report
Discuss
Answer: Option C
Explanation:
The array_splice() function removes all elements of an array found within a specified range.
A. 4hello2
B. 4
C. 2
D. 6
View Answer
Workspace
Report
Discuss
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.
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.
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.
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.
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
1. <?php
2. $cars = array("Volvo", "BMW", "Toyota");
3. echo "I like " . $cars[2] . ", " . $cars[1] . " and " . $cars[0] . ".";
4. ?>
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’.
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.
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. ?>
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.
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. ?>
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().
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.
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. ?>
Answer: b
Explanation: Simple definition of array and using it in a string. We have used $names[1] twice
and hence Bob appears twice.
1. <?php
2. $names = array("Sam", "Bob", "Jack");
3. echo $names[0]."is the brother of ".$names[1]." and
".$names[1].".".$brother;
4. ?>
Answer: d
Explanation: $brother undeclared.
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. ?>
Answer: b
Explanation: array_merge() and array_pop() yields that result.
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. ?>
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.
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.
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.
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.
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.
1. <?php
2. $city_west = array("NYC", "London");
3. $city_east = array("Mumbai", "Beijing");
4. print_r(array_replace($city_west, $city_east));
5. ?>
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.
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.
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.
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)
b)
c)
d)
1. <?php
2. $cars = array("Volvo", "BMW", "Toyota");
3. echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
4. ?>
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.
1. <?php
2. $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
3. print_r(array_change_key_case($age, CASE_UPPER));
4. ?>
Answer: c
Explanation: The array_change_key_case() function changes all keys in an array to lowercase or
uppercase.
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.
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. ?>
Answer: b
Explanation: The array_combine() function creates an array by using the elements from one
“keys” array and one “values” array.
1. <?php
2. $a = array("A", "Cat", "Dog", "A", "Dog");
3. print_r(array_count_values($a));
4. ?>
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. ?>
Answer: a
Explanation: The array_diff() function compares the values of two (or more) arrays, and returns
the differences.
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)
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.
1. <?php
2. $a1 = array("red", "green");
3. $a2 = array("blue", "yellow");
4. print_r(array_merge($a1, $a2));
5. ?>
Answer: c
Explanation: The array_merge() function merges one or more arrays into one array.
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.
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.
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.
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.
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().
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.
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.
1. <?php
2. $fruits = array ("apple", "mango", "peach", "pear",
3. "orange");
4. $subset = array_slice ($fruits, 2);
5. print_r ($subset);
6. ?>
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.
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
Explanation: A multidimensional array is an array with more than two dimensions. In a matrix, the two dimensions are represented
by rows and columns
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.
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.
Explanation: The function array_count_values() will count all the values of an array.
<?php
?>
A. 0
B. Garbage value
C. 3
D. No Output
View Answer
Ans : D
<?php
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.
<?php
Explanation: is_array() Function can be used to verify if a variable is an array. Returns TRUE or FALSE.
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.
Explanation: array_count_values() Returns the values and the frequency of each value in form of an array.
<?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
next($fruits);
next($fruits);
prev($fruits);
?>
A. guava
B. banana
C. orange
D. pine-apple
View Answer
Ans : C
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.
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
a. One dimensional
c. No indexes
d. 1 element
25. Three ways to create an array is Direct assignment, array ( ) construct and
d. None of them
i) state[0] = “karnataka”;
ii) $state[] = array(“karnataka”);
iii) $state[0] = “karnataka”;
iv) $state = array(“karnataka”);
c. Only i)
<?php
$states = array("karnataka" => array
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
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()
a. 3
b. 4
c. 5
d. 6
Answer: (d).6
a. count()
b. array_count()
c. array_count_values()
d. count_values()
Answer: (c).array_count_values()
c. Array ( 35 37 43 )
d. Array ( [35] => Peter [37] => Ben [43] => Joe )
Answer: (d).Array ( [35] => Peter [37] => Ben [43] => Joe )
Answer: (a).Array ( [A] => 5 [Cat] => 2 [Dog] => 2 [Tiger] => 1 )
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 )
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 )
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 )
?>
d. Error
c. $brother
d. Error
Answer: (d).Error
c. Array ( [0] => NYC [1] => LA [2] => Paris [3] => Paris )
Answer: (a).Array ( [0] => LA [1] => Paris [2] => Paris )
a. Array ( [red] => red [green] => green [blue] => blue [yellow] => yellow )
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");
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 )
a. 024
b. 120
c. 010
d. 060
Answer: (b).120
a. a
b. b
c. c
d. d
Answer: (c).c
print_r(array_replace($city_west, $city_east));
?>
a. Lucy
b. Peter
c. Susan
d. Edmund
Answer: (b).Peter
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 )
Answer: (a).Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
a. Array ( [0] => red [1] => green [2] => blue [3] => yellow )
b. Array ( [0] => blue [1] => yellow [2] => red [3] => green )
Answer: (a).Array ( [0] => red [1] => green [2] => blue [3] => yellow )
}
?>
?>
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);
?>
c. Array ( 35 37 43 )
d. Array ( “[Peter] => 35” “[Ben] => 37” “[Joe] => 43” )
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 )
<?php
"Andhra Pradesh");
?>
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).
<?php
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.
<?php
"banana");
?>
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.
a) count()
b) array_count_values()
c) array_count()
d) count_values()
Answer: b
Explanation:None.
Sanfoundry Global Education &
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.
i) state[0] = “karnataka”;
ii) $state[] = array(“karnataka”);
iii) $state[0] = “karnataka”;
iv) $state = array(“karnataka”);
<?php
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
Ans : B
Ans : D
Ans : A
Explanation: This trim() function allows us to remove whitespaces or strings from both
sides of a string.
<?php
?>
A. 4
B. 5
C. 6
D. 7
Ans : C
<?php
?>
A. int(13)
B. char(14)
C. int(14)
D. int(15)
Ans : C
Explanation: var_dump() cuts off loop after getting the same element three times is true
about var_dump() function.
Ans : C
Explanation: The strcasecmp() function compares the two strings s1 and s2, ignoring the
case of the characters.
Explanation: Returns a string arguments with trilling blank space removed, is a behavior
of chop ( ) function and rtrim ( ) function
<?php
$username = "letsfindcourse";
if (preg_match("([^a-z])",$username))
else
A. Error
B. No Output
C. Name must be all lowercase!
D. Name is all lowercase!
Ans : D
<?php
$str="chess was played";
echo strlen(substr($str,3,2))."
"
?>
A. 1
B. 2
C. 3
D. Array
Ans : B
<?php
echo count_chars("AA",1);
?>
A. 2
B. [65]=>2
C. Array
D. None of the above
Ans : C
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
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.
A. crc32()
B. crypt()
C. heb32()
D. heb32c()
Ans : A
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
<?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)
<?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: There are three main parameters to the code, namely the initialization, the test
condition and the counter.
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.
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.
<?php
for ($num = 1; $num <= 10; $num += 2) {
?>
A. 1 3 5 7 9
B. 1 2 3 4 5
C. 9 7 5 3 1
D. Error
View Answer
Ans : A
<?php
$num = 20;
$num += 2;
?>
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.
<?php
$num = 2;
do {
$num += 2;
?>
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.
<?php
?>
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.
<?php
do
print "LFC";
while(10);
?>
A. LFC
B. I LOVE WEBSITE
C. LFC I LOVE WEBSITE
D. infinite loop
View Answer
Ans : D
<?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
<?php
print "LFC
";
?>
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
print ++$num;
?>
A. 111213141516171819202122
B. 11121314151617181920
C. 1112131415161718192021
D. infinite loop
View Answer
Ans : A
<?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
<?php
if ($i > 1)
continue;
echo("Hi
");
?>
<?php
$i = 0;
$j = 0;
$i++;
$j++;
echo("loop
");
if($j%2==0)
continue;
goto first;
?>
<?php
$i = $i+1;
echo "$i";
?>
A. 5
B. 6
C. 7
D. 8
View Answer
Ans : B
<?php
$a = 10;
$b = $a>2?"Hi":"Bye";
echo "$b";
?>
A. HiBye
B. Bye
C. Hi
D. Error
View Answer
Ans : C
<?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.
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)
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.
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.
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.
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.
1. <?php
2. for ($i++; $i == 1; $i = 2)
3. print "In for loop ";
4. print "After loop\n";
5.
6. ?>
1. <?php
2. for (1; $i == 1; $i = 2)
3. print "In for loop ";
4. print "After loop\n";
5. ?>
1. <?php
2. for ($i == 2; ++$i == $i; ++$i)
3. print "In for loop ";
4. print "After loop\n";
5. ?>
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.
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.
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.
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
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.
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.
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.
1. <?php
2. $i = "";
3. while ($i)
4. {
5. print "hi";
6. }
7. while($i < 8)
8. $i++;
9. print "hello";
10. ?>
Explanation: PHP as it is known today is actually the successor to a product named PHP/FI.
Created by Rasmus Lerdorf
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.
Explanation: The Latest Version of PHP is 7.2 and the Release date is 30 November 2017.
Explanation: PHP files can contain text, HTML, CSS, JavaScript, and PHP code.
Explanation: PHP 7 supports new operators (like the spaceship operator: <=> )
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.
<?php
$x = 8;
$y = 8.0;
?>
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.
Explanation: PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
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.
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?
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.
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.
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.
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.
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.
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.
1. <?php
2. $num = 10;
3. echo 'What is her age? \n She is $num years old';
4. ?>
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.
i) if 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. ?>
i) for 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.
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. <?php
2. define("GREETING", "PHP is a scripting language", true);
3. echo GREETING;
4. echo "<br>"
5. echo GREETING;
6. ?>
GREETING
GREEtING
c) GREETING
d)
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.
a)
b) GREETING_TESt
c) PHP is a scripting language
d)
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.
1. <?php
2. define("__LINE__", "PHP is a scripting language");
3. echo __LINE__;
4. ?>
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.
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.
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.
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.
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.
<?php
?>
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
<?php
$five = 5;
print($five);
print $five;
?>
A. 05
B. 55
C. 50
D. Error
View Answer
Ans : B
<?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.
<?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.
<?php
print("I"."am"."learning"."php");
?>
A. Iamlearningphp
B. I am learning php
C. Nothing
D. error
View Answer
Ans : A
<?php
?>
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)
<?php
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.
<?php
print_r($arr[0]);
?>
A. Portal
B. Letsfindcourse
C. Error
D. No Output
View Answer
Ans : B
<?php
?>
A. This is letsfindcourse
B. This is "letsfindcourse"
C. Error
D. No Output
View Answer
Ans : B
<?php
?>
Explanation: the output of the following PHP code Syntax Error, unexpected echo
statement.
<?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.
<?php
echo "This","is"&"a","PHP"."MCQs";
?>
A. ThisisaPHPMCQs
B. Thisis PHPMCQs
C. This aPHPMCQS
D. ThisaPHPMCQs
View Answer
Ans : D
<?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 ($)
Explanation: A variable can have long descriptive names (like $factorial, $even_nos) or
short names (like $n or $f or $x)
Explanation: A variable name can only contain alphanumeric characters and underscores in
their name.
Explanation: One must keep in mind that variable names in PHP must start with a letter or
underscore and should not start with numbers.
Explanation: PHP variables are case-sensitive, i.e., $lfc and $LFC are treated differently.
Explanation: Depending on the scopes, PHP has three variable scopes: Local, Global and
static variable scope.
<?php
$x = 1;
$y = 2;
$z = "$x + $y";
echo "$z";
?<
A. $x + $y
B. 3
C. 1+2
D. 12
View Answer
Ans : C
<?php
$x = 3.3;
$y = 2;
echo $x % $y;
?>
A. 1.3
B. 1
C. 0
D. Error
View Answer
Ans : B
<?php
$a = 1;
$b = 2;
$c = 3;
?>
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.
<?php
$a = 1;
$b = 2;
$c = 3;
?>
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.
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.
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.
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.
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.
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.
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
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: The first five are called simple data types and the last three are compound
data types.
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.
<?php
if(TRUE)
if(FALSE)
?>
Explanation: This condition is TRUE is 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
<?php
$x1 = 10.58;
$x2 = 21.18;
echo $sum;
?>
A. 31
B. 32
C. 31.00
D. 31.76
View Answer
Ans : D
<?php
?>
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?
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.
Answer:.php
Explanation: To run a php file on the server, it should be saved as AnyName.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.
i) Notepad
ii) Notepad++
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.
i) Adobe Dreamweaver
ii) XAMPP
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.
Answer:d
Explanation: PHP 5 version and later versions added support for Exception Handling.
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?
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.
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.
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.
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.
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?
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.
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.
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.
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.
Answer:b
Explanation: a += b is an addition assignment whose outcome is a = a + b. Same can be
done with subtraction, multiplication, division etc.
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.
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.
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.
Answer:b
Explanation: PHP treats \n as a newline character.
1. <?php
2. $num = 10;
3. echo 'What is her age? \n She is $num years old';
4. ?>
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.
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.
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. ?>
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
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.
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.
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.
Answer:a
Explanation: PHP was originally created by Rasmus Lerdorf in 1994.
<php
$tax=10.3;
$TV="10.3+$TV"; # Line 1
?>
A. Integer
B. String
C. Unknown
D. No Output
Answer: B
echo gettype($TV);
?>
A. Integer
B. String
C. Unknown
D. Null
Answer : D
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
Answer: A
E. Never
Answer: C
A.Pond-sign
B.Yen-sign
C.Dollar-sign
D.Euro-sign
Answer: C
A.True
B.False
Answer: A
A. $_10
B . ${“MyVar”}
C. &$something
D .$10_somethings
E. $aVaR
Answer: C
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
A.single quotes
B.double quotes
C.both A and B
D.none of above
Answer: C