PHP MCQ
PHP MCQ
Answer:
Option (d)
2. PHP files have a default file extension of_______ (a) .html
(b) .php
(c) .prepro
(d) .phpe
Answer:
Option (b)
3. Which of the following PHP statement/statements will store 111 in variable num?
i) int $num = 111; ii) int mum = 111; iii) $num = 111; iv) 111 = $num;
(a) Both i) and ii)
(b) i), ii), iii) and iv)
(c) Only iii)
(d) Only i)
Answer:
Option (c)
4. What will be the output of the following PHP code?
<?php $num = 1; $num1 = 2; print $num . "+". $num1; ?> (a)
3
(b) 1+2
(c) 1.+.2
(d) Error
Answer:
Option (b)
5. Which is the correct variable name : i) $3hello ii) $_hello iii) $this iv) $This
(a) Only ii)
(b) Only iii)
(c) ii), iii) and iv)
(d) ii) and iv)
Answer:
Option (d)
Answer:
Option (c)
7. What will be the output of the following PHP code?
<?php
$color = "maroon";
$var = $color[2];
echo "$var";
?>
(a) a
(b) Error
(c) $var
(d) r
Answer:
Option (d)
8. What will be the output of the following PHP code?
<?php
$total = "25 students";
$more = 10;
$total = $total + $more;
echo "$total";
?>
(a) Error
(b) 35 students
(c) 35
(d) 25 students
Answer:
Option (c)
9. What will be the output of the following PHP code?
<?php
$team = "rajkot";
switch ($team) {
case "ahemdabad":
echo "I love ahemdabad";
case "rajkot":
echo "I love rajkot";
case "morbi":
echo "I love morbi"; }
?>
(a) I love rajkot
(b) I love morbi
(c) Error
(d) I love rajkot I love morbi
Answer:
Option (d)
10. What will be the output of the following PHP code? <?php
$user = array("Ashley", "Bale", "Shrek",
"Blank"); for ($x=0; $x < count($user); $x++) {
if ($user[$x] == "Shrek") continue;
printf ($user[$x]);
}
?>
(a) AshleyBale
(b) AshleyBaleBlank
(c) ShrekBlank
(d) Shrek
Answer:
Option (b)
11. How to define a function in PHP?
(a) function {function body}
(b) data type functionName(parameters) {function body}
(c) functionName(parameters) {function body}
(d) function functionName(parameters) {function body}
Answer:
Option (d)
12. What will be the output of the following PHP code? <?php
function calc($price, $tax="")
{
$total = $price + ($price * $tax);
echo "$total";
}
calc(42);
?>
(a) Error
(b) 0
(c) 42
(d) 84
Answer:
Option (c)
13. 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) I am a
(b) I am bI am a (c) Error
(d) I am a Error
Answer:
Option (a)
14. What will be the output of the following PHP code? <?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
a();
b();
?>
(a) I am a
(b) I am bI am a (c) Error
(d) I am aI am B
Answer:
Option (d)
15. What will be the output of the following PHP code? <?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
b();
a();
?>
(a) I am a
(b) I am bI am a (c) Error
(d) I am aI am B
Answer:
Option (c)
16. 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 a
(b) I am a Error
(c) Error
(d) I am aI am B
Answer:
Option (b)
17. What will be the output of the following PHP code?
<?php
$op2 = "blabla";
function foo($op1)
{
echo $op1;
echo $op2;
}
foo("hello");
?>
(a) helloblabla
(b) hello with Error
(c) hello with notice
(d) helloblablablabla
Answer:
Option (b)
18. A function in PHP which starts with __ (double underscore) is known as __________
(a) Magic Function
(b) Inbuilt Function
(c) Default Function
(d) User Defined Function
Answer:
Option (a)
19. PHP’s numerically indexed array begin with position ___________
(a) 1
(b) 0
(c) 2
(d) -1
Answer:
Option (b)
20. Which of the following are correct ways of creating an one dimensional array? i) state[0] =
"gujarat"; ii) $state[] = array("gujarat"); iii) $state[0] = "gujarat"; iv) $state = array("gujarat");
(a) iii) and iv)
(b) ii) and iii)
(c) Only i)
(d) ii), iii) and iv)
Answer:
Option (a)
21. What will be the output of the following PHP code?
<?php
$states = array("gujarat" => array
("population" => "123456789", "capital" => "Gandhinagar"),
"Tamil Nadu" => array( "population" => "17,90,000",
"capital" => "Chennai") );
echo $states["gujarat"]["population"];
?>
(a) Gujarat 123456789
(b) 123456789
(c) 123456789 gujarat
(d) error
Answer:
Option (b)
22. Which of the following PHP function will return true if a variable is an array or false if it is not an
ar
(a) this_array()
(b) is_array()
(c) do_array()
(d) in_array()
Answer:
Option (b)
23. 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:
Option (d)
24. 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) FALSE
(c) 1
(d) 2
Answer:
Option (d)
25. What will be the output of the following PHP code? <?php
$fruits = array ("apple", "orange",
"banana"); echo (next($fruits)); echo
(next($fruits));
?>
(a) orangebanana
(b) appleorange
(c) orangeorange
(d) appleapple
Answer:
Option (a)
26. Which of the functions is used to sort an array in descending order? (a) sort
(b) asort
(c) rsort
(d) dsort
Answer:
Option (c)
27. What will be the output of the following PHP code? <?php
$fruits = array ("apple", "mango", "peach", "pear",
"orange");
$subset = array_slice ($fruits, 2);
print_r ($subset);
?>
(a) Array ( [0] => peach )
(b) Array ( [0] => apple [1] => mango [2] => peach ) (c) Array ( [0] => apple [1] => mango )
(d) Array ( [0] => peach [1] => pear [2] => orange )
Answer:
Option (d)
28. The filesize() function returns the file size in ___________
(a) bits
(b) bytes
(c) kilobytes
(d) gigabytes
Answer:
Option (b)
29. 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:
Option (c)
30. 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:
Option (b)
31. 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:
Option (a)
32. The date() function returns ___ representation of the current date and/or time.
(a) Integer
(b) String
(c) Boolean
(d) Float
Answer:
Option (b)
33. Which one of the following function outputs the contents of a string variable to the specified
resour
(a) filewrite
(b) fwrite
(c) filewrites
(d) fwrites
Answer:
Option (b)
34. which is not a predefined array in PHP
(a) $_GET
(b) $_SET
(c) $_POST
(d) $_REQUEST
Answer:
Option (b)
35. 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)
36. 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:
Option (a)
37. 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
Answer:
Option (c)
38. Which one of the following is the default PHP session name?
(a) PHPSESSID
(b) PHPSESID
(c) PHPSESSIONID
(d) PHPIDSESS
Answer:
Option (a)
39. Which function is used to destroy session data?
(a) session_destroy
(b) session_change
(c) session_remove
(d) session_unset
Answer:
Option (a)
40. PHP is an example of ___________ scripting language. (a) Server-side
(b) Client-side
(c) Browser-side
(d) in-side
Answer:
Option (a)
41. Which of the following is not true?
(a) PHP can be used to develop web applications.
(b) PHP makes a website dynamic (c) PHP applications can not be compile
(d) PHP can not be embedded into html.
Answer:
Option (d)
42. Which of the following method sends input to a script via a URL? (a) GET
(b) POST
(c) BOTH
(d) NONE
Answer:
Option (a)
43. 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)
44. Which of the following function returns the number of characters in a string variable?
(a) count($variable)
(b) len($variable)
(c) strcount($variable)
(d) strlen($variable)
Answer:
Option (d)
45. Array with string index in php is called as ______
(a) numeric array
(b) string array
(c) associative array
(d) generic array
Answer:
Option (c)
46. How to redirect to other page in PHP
(a) using header fuction
(b) using location object
(c) using Response.redirect method
(d) all of above
Answer:
Option (a)
47. How can we identify browser in PHP
(a) using $_BROWSER['name']
(b) using $_SERVER['NAVIGATOR_NAME']
(c) using $_SERVER['HTTP_USER_AGENT']
(d) using $_BROWSER['version']
Answer:
Option (c)
48. What is default access specifiers in PHP
(a) default
(b) protected
(c) private
(d) public
Answer:
Option (d)
49. How to set cookie in PHP
(a) using $_COOKIE
(b) using setcookie method
(c) using $_SETCOOKIE
(d) none of above
Answer:
Option (b)
50. The updated MySQL extension released with PHP 5 is typically referred to as ________.
(a) MySQL
(b) mysql
(c) mysqli
(d) mysqly
Answer:
Option (c)