PHP MCQ
PHP MCQ
Answer: (c) . (dot)
Description: In PHP, the . (dot) operator is used for
concatenation. Suppose there are two variables $a and $b, so the
statement $a . $b will concatenate both $a and $b.
Answer: (c) uniqueid()
Description: We can declare and call user-defined functions
easily. The syntax to declare user-defined functions is given
below -
function functionname(){
//code to be executed
}
20) Which of the following is the correct way to open the file
"sample.txt" as readable?
a. fopen("sample.txt", "r");
b. fopen("sample.txt", "r+");
c. fopen("sample.txt", "read");
d. fopen("sample.txt");
Answer: (b) phpinfo()
Description: The phpinfo() function gives us the information
about the PHP configuration and installation in our system. The
phpinfo() function is generally used to check the configuration
settings.
Answer: (a) glob()
Description: The glob() function in PHP is used to return an
array of filenames or directories that matches a specified pattern.
Answer: (c) setcookie()
Description: PHP cookie is a small piece of information that is
stored at client browser. It is used to recognize the user. PHP
setcookie() function is used to set cookie with HTTP response.
Once the cookie is set, you can access it by the $_COOKIE
superglobal variable.
Answer: (b) unset()
Description: The unset() function is a predefined variable
handling function of PHP, which is used to unset a specified
variable. In other words, "the unset() function destroys the
variables".
Answer: (b) gettype()
Description: The gettype() function is an inbuilt function in
PHP, and as its name implies, it returns the type of a variable.
The gettype() function in PHP is used to check the type of
existing variable.
Answer: (c) $new-var
Description: In PHP, a variable is declared using a $ sign
followed by the variable name. A variable name must start with
a letter or underscore (_) character.
A PHP variable name cannot contain spaces.
Answer: (a) array_push()
Description: The array_push() is a built-in function of PHP. This
function helps the users to add the elements at the end of the
array. It allows to insert any number of elements in an array.
Even you can add a string as well as numeric values.
Answer: (b) ucwords($var)
Description: The ucwords() is an in-built function of PHP,
which is used to convert the first character of each word to
uppercase in a string. It takes a string as an input and converts
the first character of each word of the string to uppercase. The
other characters of the string remain the same.
Answer: (d) strtoupper()
Description: The strtoupper() is one of the most popular
functions of PHP, which is widely used to convert the string into
uppercase. It takes a string as a parameter and converts all
lowercase English character of that string to uppercase.
Answer: (b) fileatime()
Description: The fileatime() function in PHP is used to return
the last access time of a file as a UNIX timestamp. On failure,
the fileatime() returns false.
Answer: (c) fgets()
Description: The PHP fgets() function is used to read a single
line from the file.
42) Which PHP function is used to find the position of the last
occurrence of a substring inside another string?
a. strops()
b. strrpos()
c. strtr()
d. None of the above
Answer: (b) strrpos()
Description: The strrpos() is an in-built function of PHP which
is used to find the position of the last occurrence of a substring
inside another string. It is a case-sensitive function of PHP,
which means it treats uppercase and lowercase characters
differently.
Answer: (a) HelloWorld
Description: In the given echo statement, both variables are
inside the double quotes, so the variable's value will be
substituted and printed on the screen.
Answer: (b) 1
Description: In the given program there is post-increment. So,
first, the condition is checked, therefore at first, the value 0 is
tested and does not enter the loop. So, the program will print 1.
49) What will be the output of the following program?
1. <?php
2. echo ucwords("welcome to the javaTpoint.com");
3. ?>
a. Welcome to the javaTpoint.com
b. welcome to the javaTpoint.com
c. Welcome To The JavaTpoint.com
d. Welcome to the JavaTpoint.com
Answer: (a) 2015
Description: In the given program, first the show() function is
called, and the variable $a is initialized to 20, and 20 is printed
on the screen. Later, the global variable $a is initialized to 15,
and the value 15 is printed on the screen. So the output of the
above program will be 2015.
Answer: (d) Error
Description: The while loop is also called an Entry control loop
because the condition is checked before entering the loop body.
This means that first, the condition is checked. If the condition is
true, the block of code will be executed. So, a while loop cannot
be defined without a condition.
Answer: (b) array_diff
Description: The array_diff() function compares two or more
arrays and returns an array with the keys and values from the
first array, only if the value is not present in any of the other
arrays.
Answer: (c) strtotime()
Description: The PHP strtotime() function is used to convert an
English text datetime into a Unix timestamp.
Answer: (a) date_sunrise()
Description: This date_sunrise() function is used to get the
timing of sunrise of a particular day and location. This function
returns the sunrise time of different locations.