Explore topic-wise MCQs in Php.

This section includes 20 Mcqs, each offering curated multiple-choice questions to sharpen your Php knowledge and support exam preparation. Choose a topic below to get started.

1.

Which of the following advanced OOP features is/are not supported by PHP? (i) Method overloading (ii) Multiple Inheritance (iii) Namespaces (iv) Object Cloning

A. All of the mentioned
B. (iii) and (iv)
C. (i) and (ii)
D. None of the mentioned
Answer» D. None of the mentioned
2.

Which of the following is/are the right way to declare a method? (i) function functionName() { function body } (ii) scope function functionName() { function body } (iii) method methodName() { method body } (iv) scope method methodName() { method body }

A. Only (ii)
B. Only (iv)
C. (i) and (ii)
D. (iii) and (iv)
Answer» D. (iii) and (iv)
3.

Which one of the following is the right way to call a class constant, given that the class is mathFunction?

A. echo PI;
B. echo mathFunction->PI;
C. echo mathFunction::PI;
D. echo mathFunction=PI;
Answer» D. echo mathFunction=PI;
4.

Which keyword is used to refer to properties or methods within the class itself?

A. private
B. public
C. protected
D. $this
Answer» E.
5.

In the PHP code given below, what is/are the properties? < ?php class Example { public $name; function Sample() { echo "This is an example"; } } ?>

A. echo “This is an example”;
B. public $name;
C. class Example
D. function sample()
Answer» C. class Example
6.

PHP recognizes constructors by the name.

A. classname()
B. _construct()
C. function _construct()
D. function __construct()
Answer» E.
7.

What will be the output of the following PHP code? < ?php echo str_pad("Salad", 5)." is good."; ?>

A. SaladSaladSaladSaladSalad is good
B. is good SaladSaladSaladSaladSalad
C. is good Salad
D. Salad is good
Answer» E.
8.

How many functions does PHP offer for searching strings using POSIX style regular expression?

A. 7
B. 8
C. 9
D. 10
Answer» B. 8
9.

PHP has long supported two regular expression implementations known as ___ and ___. (i) Perl (ii) PEAR (iii) Pearl (iv) POSIX

A. (i) and (ii)
B. (ii) and (iv)
C. (i) and (iv)
D. (ii) and (iii)
Answer» D. (ii) and (iii)
10.

Which one of the following functions finds the last occurrence of a string, returning its numerical position?

A. (a) strlastpos()
B. strpos()
C. strlast()
D. strrpos()
Answer» E.
11.

Which one of the following functions can be used to concatenate array elements to form a single delimited string?

A. explode()
B. implode()
C. concat()
D. concatenate()
Answer» C. concat()
12.

Which one of the following functions will convert a string to all uppercase?

A. strtoupper()
B. uppercase()
C. str_uppercase()
D. struppercase()
Answer» B. uppercase()
13.

Say we have two compare two strings which of the following function/functions can you use? (i) strcmp() (ii) strcasecmp() (iii) strspn() (iv) strcspn()

A. (i) and (ii)
B. (iii) and (iv)
C. None of the mentioned
D. All of the mentioned
Answer» E.
14.

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

A. bits
B. bytes
C. kilobytes
D. gigabytes
Answer» C. kilobytes
15.

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

A. last()
B. before()
C. prev()
D. previous()
Answer» D. previous()
16.

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» E.
17.

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» C. do_array()
18.

What will be the output of the following php code? < ?php $states = array("karnataka" => array ( "population" => "11,35,000", "captial" => "Bangalore"), "Tamil Nadu" => array( "population" => "17,90,000", "captial" => "Chennai") ); echo $states["karnataka"]["population"]; ?>

A. karnataka 11,35,000
B. 11,35,000
C. population 11,35,000
D. karnataka population
Answer» C. population 11,35,000
19.

What will be the output of the following PHP code? < ?php $fruits = array ("mango", "apple", "pear", "peach"); $fruits = array_flip($fruits); echo ($fruits[0]); ?>

A. mango
B. Error
C. peach
D. 0
Answer» C. peach
20.

PHP’s numerically indexed array begin with position __.

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