PHP MCQ Question and Answer
Chapter-1,2,3 & 4:
1. What is the difference between $message and $$message?
- $message is a simple variable whereas $$message is a reference variable.
- $message is a simple variable whereas $$message is a Object variable.
- $message is a simple object whereas $$message is a static variable.
2. How do we declare constants variable?
- constants $varname
- $varname constants
- define()
- $$varname
3. What are the difference between print and echo?
- echo faster than print
- echo return value
- print return value
- echo return true
Ans: A,C4. ______________ data type are used to represent a single value.
- Boolean
- Scalar
- Number
- String
5. Which are the example of compound data type?
- array
- object
- String
- Float
6. Which statement is true about Type Juggling?
- Varibles are sometimes automatically cast.
- Convert on data type to another
- Convert to object to Data Type
7. How to get the type of the variable?
- using getDataType function
- using gettype function
- datatype()
- function
- settype() function
8. How to convert types?
- using getDataType function
- using gettype function
- datatype() function
- settype() function
9. Which of the example is reference assignment?
- $value=”Hello” $value2=$value
- $$value=”Hello” $value2=$value
- $value=”Hello” $value2=&$value
10. PHP comments for a single line have the following syntax:
- /* comments /*
- #
- //
- ::
- A&B
11) In PHP, instructions are terminated with a _______.
- ;
- #
- !
- %>
12) What is the correct way to create a function in PHP?
- function myFunction()
- new_function myFunction()
- create myFunction()
13) What is the correct way to add 1 to the $count variable?
- count++;
- $count++;
- ++count
- $count =+1
14) What does break; do?
- Ends execution of the current switch structure
- Moves on to the next iteration of the current for, foreach, while, do-while or switch structure
- Ends execution of the current for, foreach, while, do-while or switch structure
15) Which operator is used to concatenate two strings in php?
- dot operator (.)
- plus operator (+)
16) Which of the following function is used for terminate the script execution in PHP?
- break()
- quit()
17) <?php
define("x","5");
$x=x+10;
echo x;
?>
A. Error
- 15
- 10
- 5
18. How to returns any ensuring value back to the function caller?
- using break statement
- using return statement
- using Continue Statement
19. Which function call themselves?
- Reference Function
- Recursive Function
- Function within Function
20. Which statement will evaluate and include a file into the location where it is called.
- include() statement
- Inc statement
- Requrired_once Statement
21. What are the General Features of PHP?
- A. Practicality
- B. Power
- C. Price
- D. Improved Resource Handling
- E. Possibility
22. What is web Default server of PHP?
- A. Apache
- B. IIS
- C. PCRE
- D. PHPLIB
23. What is additional features in PHP5?
- A. Session Handling
- B. String Handling
- C. SQLite
- D. Webserives
24. What is Stand for WAMP server?
- A. Windows Application mySQLPHP
- B. Windows Apache MySQL PHP
- C. Windows Application amd MySQL PHP
- D. Windows Apache Microsoft PHP
Ans: B25. What command is used manipulating PHP configuration Variable?
A. Unset()
B. ini_set()
C.php_conf
Ans: B
Chapter-5
1. — Creates an array by using one array for keys and another for its values
A. Array_Splice
B. . array_combine
C. Array_Fill()
Ans: B
2. Which statement are true about Array?
A. An array is traditionally defined as a group of items that share certain characteristics
C. Offer considerable practical value to the programmer and are used to divide an otherwise complex.
Ans: A,B
3. Which function use to remove a portion of the array and replace it with something else
A. Array_Splice
B. array_combine
C. Array_Fill()
Ans: A
4. How to remove duplicate from an array?
A.Array_Duplicate
B. Array_Unique
C. Array_Push()
Ans: B
5. <?php$a[0] = 1;$a[1] = 3;$a[2] = 5;$result = count($a);What will be the output
A. 3 B. 4 C.2 Ans: A6. Which function use to check if a value exists in an array?A. Array_In () B. Array_check() C. Array_Fill()Ans: A7. Which function use to sort an array by key in reverse orderA. Sort() B. ksort() C. Krsort() D.array_reverse()Ans: C8. How to searches the array for a given value and returns the corresponding key if successfully?
A. Array_in()
B. Search()
C. Array_Search()
Ans: C
9. <?php
$stack = array("orange", "banana", "apple", "raspberry");
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_pop($stack);
print_r($stack);
?>
print_r($stack);
?>
What will be the output?
A. [0] => orange [1] => banana [2] => apple
B. [0] => orange [1] => banana [2] => raspberry
C. [0] => raspberry [1] => banana [2] => apple
Ans: A
10. <?php
$array = array("size" => "XL", "color" => "gold");
print_r(array_values($array));
?>
$array = array("size" => "XL", "color" => "gold");
print_r(array_values($array));
?>
What will be the output?
A. [0] => XL [1] => gold [2]=>Size
B. [0] => XL [1] => gold
Ans: B
11. ksort— Sort an array with a user-defined comparison function and maintain index association
A. True
B. False
Ans: B
12. ________Return the current key and value pair from an array and advance the array cursor.
A. Prev
B. Next
C. Last
D. Each
Ans: D
13. Which construct used to make simultaneously variable assignments from values extracted from an array?
A. Array_list()
B. list ()
C. list_array()
Ans: B
14. A key may be either an integer or a string. If a key is the standard representation of an integer
A. True
B. False
Ans: A
15. Which function adds element to the front of array?
A. Shift()
B. Unshift()
C. push()
D. Pop()
Ans: B
Chapter-6 & 7
1. Which of the following is not a part of OOP?
A. Type checking
B. Inheritance
C. Polymorphism
D. Encapsulation
Ans: A
2. Which one of the following terms must relate to "Object"
A. Static allocation.
B. Specific instance of the class models.
C. Code component.
D. Attributes of a class.
Ans: B
3. Abstract class objects never have to be instantiated.
A. True
B. False
Ans : A
4. A constructor is used to...
A. Free memory.
B. Initialize a newly created object.
C. Import packages.
D. Create a JVM for applets.
Ans: B
5. What is the purpose of the Properties?
A. To build a user interface.
B. To build Object
C. to describe some aspect of a class.
D. Noe of the Above
Ans: C
6. Which of the following line is used to create new Object?
A. employee $emp=new employee();
B. $employee =new Employee();
C. employee =new $Employee();
Ans: B
7. Which of the following are class property scope?
A. Private
B. Public
C. Declare
D. Protected
Ans: A,B, D
8. PHP support six method scope. Which of the following are method scope.
A. Private
B. Public
C. Declare
D. Protected
Ans: A,B, D
9. How to declare a constructor?
A. function __construct($ein)
{
}
B. function construct($ein)
{
}
C. function employee($ein)
{
}
Ans: A
10. Which of the following statements are true about constructors?
A. Constructor is defined as block of code that automatically executes at the time of object instantiation.
B. Constructor can accept parameters.
C. Constructor ensures that the object being passed to the method.
B. Class constructors cannot call on other constructors.
Ans: A,B
11. How to determine whether an object is an instance of a class?
A. using new keyword
B. using instanceof keyword
C. using static keyword
Ans: B
12. The ability to implement polymorphism through method overloading is not supported by php
A. True B. False
Ans: A
13. Which line of code use to clone a object?
A. $drone1=new Corproate_Drone()
$drone2=copy $drone1
B. $drone1=new Corproate_Drone()
$drone2=object $drone1
C. $drone1=new Corproate_Drone()
$drone2=clone $drone1
Ans: C
14. Which class defines a general specification for implementing a particular service, declaring the required functions and constants without implementation code?
A. constants
B. Interface
C. Abstract
Ans : B
15. Which methods are special in that they are declared only within a parent class but are implement child class ?
A. Static method
B. Constants Method
C. Private method
D. Abstract Method
Ans : D
16. What are the two common characteristics shared by all objects?
A. Methods and interfaces
B. State and behavior
C. Methods and messages
Ans: B
Chapter- 8
1. Which statement are true about Exception Handling?
A. Definition of error.
B. Exceptions are used to change the normal flow of a script if a specified error occurs.
C. Exceptions should only be used with error conditions
Ans: B,C
2. How to get the name of the file throwing the exception?
A. getFile()
B. getName()
C. getCode()
D. getMessage()
Ans: A
2. How to get the line number for which the exception is thrown?
A. getFile()
B. getName()
C. getCode()
D. getLine()
Ans: D
3. Which of the following statement is the default exception constructor?
A. thrown Exception()
B. throw new Exception()
C. throw new $Exception()
Ans: B
4. During the developing stage, which of the directive used for all errors to be reported?
A. error_reporting=All_error & E_strict
B. E_All | E_Parse
C. error_reporting=E_All & E_STRICT
D. None of the above
Ans: C
5. Which features determine the language’s error – handling behavior.
A. Error Logging
B. Exception Handling
C. Configuration
D. All of the above
Ans: C
Chapter- 9
1. PHP supported two regular expression –
A. POSIX
B. Unix
C. Perl
D. Pear
Ans : A, C
2. Which statement is true about Regular Expressions?
A. describing or matching data according to defined syntax rules
B. allowing to slice and dice text in nearly every conceivable fashion.
C. Used for searching data
Ans: A
3. Which function executes a case-sensitive search of a string for defined pattern?
A. eregi()
B. ereg()
C. pereg()
D. peregI()
Ans: B
4. Which function executes a case-insensitive search of a string for defined pattern?
A. eregi()
B. ereg()
C. pereg()
D. peregI()
Ans: A
5. Which function used to find and replace pattern with a replacement string.
A. eregi_replace()
B. ereg()
C. replace_string()
D. peregI()
Ans: A
6. How to divide a string into various elements?
A. using string_divide()
B. Substring()
C. Split()
D. Str()
Ans: C
7. Which function searches all elements of an array, returning an array()
A. using array_Search()
B. Search()
C. preg_grep()
D. Str()
Ans: C
8. ___________ function searches a string for a specific pattern, returning TRUE if it exists.
A. preg_search()
B. preg_find()
C. preg_match()
Ans: C
9. Spliting a string into various elements based on Case-Insensitive pattern_
A. preg_search()
B. preg_find()
C. ereg_split()
D. preg_split()
Ans: D
10. How to determine the length of a string?
A. strlen($str)
B. strLength($str)
C. strLength($str)
D. None of the above
Ans: A
11. Comparing two strings case insensitively, which of the following function is used?
A. strCompare($str1,$str2)
B. strcasecmp($str1,$str2)
C. compare($str1,$str2)
D. None of the above
Ans: B
12. How to convert a string to lowercase?
A. Stringtolower($str)
B. tolower($str)
C. strtolower($str)
D. lower($str)
Ans: C
13. How to convert a string to Uppercase?
A. Stringtolower($str)
B. tolower($str)
C. strtoupper($str)
D. lower($str)
Ans: C
14. How to capitalize each word?
A. Stringtoupperr($str)
B. tocapitalize($str)
C. strtoupper($str)
D. ucword($str)
Ans: D
15. Which function use to convert html tag to plain text?
A. strip_tags($input)
B. strip_html ($input)
C. tag_strip($input)
Ans: A
