/* */ Click to Join Live Class with Shankar sir Call 9798158723

PHP MCQ



Q1. PHP is a _______?
  1. Open Source Language
  2. Widely used language
  3. Server side scripting language
  4. All of the above

Answer:- (4).
Q2. Which of the following symbol is used to add multiple line comments in PHP ?
  1. //
  2. /* */
  3. {{ }}
  4. {/ \}

Answer:- (2).
Q3. Which sign is used to access variable of variable in PHP ?
  1. $$
  2. $
  3. #@
  4. $|

Answer:- (1).
Q4. Which function is used to get ASCII value of a character in PHP ?
  1. asc()
  2. chr()
  3. ascii()
  4. val()

Answer:- (2).
Q5. Which function in PHP is used to get the length of the string variable ?
  1. count()
  2. strcount
  3. strlen
  4. len

Answer:- (3).
Q6. Who is the father of PHP ?
  1. Drek Kolkevi
  2. Rasmus Lerdorf
  3. William Makepiece
  4. List Barely

Answer:- (2).
Q7. Which of the following PHP functions accepts any number of parameters ?
  1. func_get_args()
  2. func_get_argv()
  3. get_argv
  4. get_argc()

Answer:- (1).
Q8. PHP stands for_____ ?
  1. Personal Home Page
  2. Hypertext pre-processor
  3. Pro Hypertext-preprocessor
  4. None of the above

Answer:- (2).
Q9. Which of the following variables is not a pre-defined variable in PHP ?
  1. $GET
  2. $POST
  3. $REQUEST
  4. $ASK

Answer:- (4).
Q10. Which of the following is used to create a session ?
  1. $_SESSION[]
  2. isset() function
  3. session_start() function
  4. session_destroy() function

Answer:- (3).
Q11. Using which of the following way can you embed PHP code in an HTML page ?
  1. <?php PHP code goes here ?>
  2. < PHP code goes here ?>
  3. <script language="php"> PHP code goes here </script>
  4. All of the above

Answer:- (4).
Q12. Which of the following variable is used to generate random numbers using PHP ?
  1. srand()
  2. rand()
  3. random()
  4. None of the above

Answer:- (2).
Q13. Which of the following method can be used to create a MySQl database using PHP ?
  1. mysql_connect()
  2. mysql_query()
  3. mysql_close()
  4. None of the above

Answer:- (2).
Q14. What will happen in this function call ?
<?php
function calc($price, $tax)
{
	    $total = $price + $tax;
}
$pricetag = 15;
$taxtag = 3;
calc($pricetag, $taxtag);
?>
  1. Call By Value
  2. Call By Reference
  3. Default Argument Value
  4. Type Hinting

Answer:- (A).
Explanations :When you pass an argument in the above manner or say we pass 15 and 3 directly, it is called passing by value or call by value.
Q15. Which of the following function is capable of reading a specifice number of characters form a file ?
  1. fgets()
  2. fget()
  3. fileget()
  4. filegets()

Answer:- (D).
Q16. When you use the $_GET variable to collect data, the data is visible to ?
  1. none
  2. only you
  3. everyone
  4. selected few

Answer:- (3).
Q17. Which variable is used to collect form data sent with both the GET and POST methods ?
  1. $BOTH
  2. $_BOTH
  3. $REQUEST
  4. $_REQUEST

Answer:- (4).
Q18. To validate an e-mail address, which flag is to be passed to the function filter_var() ?
  1. FILTER_VALIDATE_EMAIL
  2. FILTER_VALIDATE_MAIL
  3. VALIDATE_EMAIL
  4. VALIDATE_MAIL

Answer:- (1).
Q19. What will be the output of the following PHP code ?
<?php
$fruits = array ("mango", "apple", "pear", "peach");
$fruits = array_flip($fruits);
echo ($fruits[0]);
  1. mango
  2. Error
  3. peach
  4. 0

Answer:- (2).
Explanations : As we are flippling the values, $fruits["mango"] = 0, $fruits["apple"] = 1 and so on.
Q20. Which of the following is not a variable scope in PHP ?
  1. Extern
  2. Local
  3. Static
  4. Global

Answer:- (1).
Explanations :The scope of a variable is defined as its range in the program under which it can be accessed.
Q21. Which of the following is the use of strpos() function in PHP ?
  1. The strpos() function is used to search for the spaces in a string
  2. The strpos() function is used to search for a number in a string
  3. The strpos() fucntion is used to search for a character/text in a string
  4. The strpos() function is used to search for a capitalize character in a string

Answer:- (3).
Explanations :The strpos() is in-built function of PHP. It is used to find the position of the first occurence of a string inside another string or substring in a string.
Q22. What is the use of fopen() function in PHP ?
  1. The fopen() function is used to open folders in PHP
  2. The fopen() function is used to open remote server
  3. The fopen() function is used to open files in PHP
  4. None of the above

Answer:- (3).
Explanations : The fopen() function accepts two arguments: $filename and $mode. The $filename represents the file to e opened and $mode represents the file mode.
Q23. What will be the output of the following program ?
<?php
$a = 15;
function show()
{
	 $a = 20;
	 echo "$a";
}
show();
echo "$a";
?>
  1. 2015
  2. 2020
  3. 1515
  4. 0

Answer:- (1).
Explanations : 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.
Q24. What will be the output of the following program ?
<?php 
$var1="Hellow World";
echo strrev("var1");
?>
  1. dlroW olleH
  2. olleH dlroW
  3. Hello dlroW
  4. None of the above

Answer:- (1).
Explanations :The strrev() function is used to reverse a string. It is a built in PHP function.
Q25. Which of the following function is used to sort an array in descending order ?
  1. sort()
  2. asort()
  3. dsort()
  4. rsort()

Answer:- (4).
Explanations : The PHP rsort() function is used to sort an array in descending order.