Article Diary - General Knowledge Digest

PHP Quiz Questions and Answers

Some PHP quiz questions with answers to help you score good in interview of a PHP developer. The answers to these interview questions are given at the end of this page.

1) What will be the output of PHP code below?

PHP Code
<?php
$x=array("aaa","ttt","www","ttt","yyy","tttt");
$y=array_count_values($x);
echo $y[ttt];
?>

a) 2
b) 3
c) 1
d) 4

2) How do you get information from a form that is submitted using the "get" method?

a) $_GET[];
b) Request.Form;
c) Request.QueryString;
d) $_POST[];

3) What’s the best way to copy a file from within a piece of PHP?

a) Print out a message asking your user to "telnet" in to the server and copy the file for you
b) Open the input and output files, and use read() and write() to copy the data block by block until read() returns a zero
c) Use the built in copy() function
d) Use "exec" to run an operating system command such as cp (Unix, Linux) or copy (Windows)

4) PHP code is embedded directly into XHTML document?

a) False
b) True

5) Is it possible to submit a form with out a submit button?

a) Yes
b) No

6) What is the full form of PHP?

a) Pre Hypertext Processor
b) Hypertext Preprocessor
c) Hypertext Postprocessor
d) Post Hypertext Processor

7) What is the expansion of LAMP?

a) Linux and MySql PHP
b) Linux Apache MySQL PHP

8) In PHP, Which method is used to getting browser properties?

a) $_SERVER[’HTTP_USER_AGENT’];
b) $_SERVER[’PHP_SELF’]
c) $_SERVER[’SERVER_NAME’]
d) $_SERVER[’HTTP_VARIENT’]

9) Which of the following function is used to pick one or more random values from PHP Array?

a) array_rand()
b) array_random()
c) Random_array()
d) Rand_array()

10) What will be the output of PHP code below?

PHP Code
<?php
$x=array(1,3,2,3,7,8,9,7,3);
$y=array_count_values($x);
echo $y[8];
?>

a) 43
b) 1
c) 8
d) 6

11) Assume that your php file ’index.php’ in location c:/apache/htdocs/phptutor/index.php. If you used $_SERVER[’PHP_SELF’] function in your page, then what is the return value of this function?

a) phptutor/index.php
b) /phptutor/index.php
c) c:/apache/htdocs/phptutor/index.php
d) index.php

12) Which operator is used to concatenate two strings in php?

a) dot operator (.)
b) plus operator (+)

13) Are there regular expressions in PHP?

a) Yes - regular expressions use Perl-like conventions
b) Yes - PHP supports two different types of regular expressions: POSIX-extended and Perl-Compatible Regular Expressions (PCRE).
c) Yes - regular expressions use the POSIX standard
d) No - PHP uses "glob" style matching only

14) In PHP, which of the following function is used to insert content of one php file into another php file before server executes it?

a) include[]
b) #include()
c) include()
d) #include{}

15) Assume that today is 2013-10-14:2:45:32 pm. What will be the output of PHP code below?

PHP Code
<?php
$today = date("F j, Y, g:i a");
?>

a) october 14,13,2:45:32 PM
b) October 14, 2013, 2:45 pm
c) October 14,2013,14:45:32 pm
d) October 14,2013,14:45:32 PM

16) Which of the following function is used for terminate the script execution in PHP?

a) break()
b) quit()
c) die()

17) What function used to print statement in PHP?

a) echo();
b) printf
c) ""

18) What will be the output of PHP code below?

PHP Code
<?php
define("x","5");
$x=x+10;
echo x;
?>

a) Error
b) 15
c) 10
d) 5

19) What will be the output of below mentioned PHP code?

PHP Code
<?php
$arr = array(5 => 1, 12 => 2);
$arr[] = 56;
$arr["x"] = 42;
unset($arr);
echo var_dump($arr);
?>

a) 42
b) 56
c) Null
d) x=42

20) PHP variables are:

a) Multitype variables
b) Double type variables
c) Single type variable
d) Trible type variables

21) Which of these statements is true?

a) PHP interfaces to the MySQL database,and you should transfer any data in Oracle or Sybase to MySQL if you want to use PHP on the data.
b) PHP interfaces to a number of relational databases such as MySQL, Oracle and Sybase. A wrapper layer is provided so that code written for one database can easily be transferred to another if you later switch your database engine.
c) PHP interfaces to a number of relational databases such as MySQL, Oracle and Sybase but the interface differs in each case.
d) There’s little code in PHP to help you interface to databases, but there’s no reason why you can’t write such code if you want to.

22) Can PHP support multiple inheritance?

a) No
b) Yes

23) How would you add 1 to the variable $count?

a) incr count;
b) $count++;
c) $count =+1
d) incr $count;

24) Which of the following is used to check if a function has already been defined?

a) bool function_exists(functionname)
b) bool f_exists(functionname)
c) bool func_exist(functioname)

25) What is the return value of substr function in code below?

PHP Code
<?php
$rest = substr("abcdef", -1);
$rest = substr("abcdef", 0, -1);
?>

a) f,abcde
b) a,fedcb
c) b,abcdef
d) a,abcde

26) Assume that your php file ’index.php’ in location c:/apache/htdocs/phptutor/index.php. If you used basename($_SERVER[’PHP_SELF’]) function in your page, then what is the return value of this function?

a) phptutor
b) phptutor/index.php
c) index.php
d) /index.php

27) Program below will call the function display_result(). True or False?

PHP Code
<?php
$x="display";
${$x.’_result’} ();
?>

a) False
b) True
c) Parser Error
d) None of the above

28) All variables in PHP start with which symbol?

a) !
b) $
c) &
d) %

29) Who is known as the father of PHP?

a) Larry Wall
b) Rasmus Lerdorf
c) James Gosling
d) Guido Van Rossum

30) In PHP the error control operator is _______

a) .
b) *
c) @
d) &

31) What will be the output of PHP code below?

PHP Code
<?php
$str = "3dollars";
$a = 20;
$a += $str;
print($a);
?>

a) 23 dollars
b) 203 dollars
c) 320 dollars
d) 23

32) What will be the output of PHP code below?

PHP Code
<?php
function zz(& $x)
{
$x=$x+5;
}
$x=10;
zz($x);
echo $x;
?>

a) 5
b) 0
c) 15
d) 10

33) What will be the output of PHP code below?

PHP Code
<?php
echo $_SERVER[’REMOTE_ADDR’];
?>

a) Shows the IP address of the local system
b) Shows the IP address of the visitor
c) Shows the IP address of the web server
d) None of the above

34) What will be the output of following PHP code?

PHP Code
<?php
$x=dir(".");
while($y=$x->read())
{
echo $y."
"
}
$y->close();
?>

a) display all folder names
b) display a folder content
c) display content of the all drives
d) Parse error

35) What will be the output of PHP code below?

PHP Code
<?php
$qpt = ’QualityPointTechnologies’;
echo preg_match("/^Quality/", $qpt);
?>

a) 1
b) 0
c) Quality
d) Null

36) What will be the output of PHP code below?

PHP Code
<?php
$test="3.5seconds";
settype($test,"double");
settype($test,"integer");
settype($test,"string");
print($test);
?>

a) 3.5
b) 3.5 seconds
c) 3
d) 3 seconds

37) What will be the output of PHP code below?

PHP Code
<?php
$x=array(2=>"mouse",7=>"keyboard");
$y=array_keys($x);
echo $y[1];
?>

a) keyboard
b) mouse
c) 7
d) 2

38) What will be the output of PHP code mentioned below?

PHP Code
<?php
$data="98.8degrees";
(double)$data;
(int)$data;
(string)$string;
echo $data;
?>

a) 98
b) 98.8
c) 98.8 degrees
d) degrees

39) PHP is ___________

a) Partially cross-platform
b) Truly cross-platform
c) None of above

40) What will be the output of PHP code below?

PHP Code
<?php
$x="101.5degrees";
(double)$x;
(int)$x;
echo (string)$x;
?>

a) 101.5
b) degrees
c) 101
d) 101.5degrees

41) Whether one-line comment begin with hash sign(#) in php?

a) True
b) False
c) None of above

42) In PHP, during error handling include() generates ____________

a) A fatal error, and the script will stop
b) A warning, but the script will continue execution
c) None of the above

43) What will be the output of PHP code below?

PHP Code
<?php
$qpt = ’Eat to live, but not live to eat’;
echo preg_match("/^to/", $qpt);
?>

a) 0
b) 1
c) to
d) Null

44) What will be the output of PHP code below?

PHP Code
<?php
$x=array("aaa","","ccc","ddd","");
$y=array_unique($x);
echo count($x) . "," . count($y);
?>

a) 3,1
b) 3,3
c) 5,5
d) 5,4

45) PHP is a __________. It means you do not have to tell PHP which data type the variable is. PHP automatically converts the variable to the correct data type, depending on its value.

a) client side language
b) local language
c) global language
d) loosely typed language

46) Which of the following is not a valid variable name?

a) $number-in-class
b) $nic
c) $NumberInClass
d) $number_in_class

47) Which of the following function is used to change the root directory in PHP?

a) chroot()
b) change_root()
c) cd_root()
d) cd_r()

48) PHP is a __________

a) client side script language
b) server side script language
c) event-driven language

49) What will be the output of PHP code below?

PHP Code
<?php
$father = "mother";
$mother = "son";
echo $$father;
?>

a) son
b) mother
c) motherson
d) error

50) What will be the output of PHP code below?

PHP Code
<?php
$x=array(4,2,5,1,4,5,3,4);
$y=array_count_values($x);
echo count($y);
?>

a) 8
b) 5
c) 7
d) 28

51) The PHP syntax is most similar to:

a) PERL and C
b) Java script
c) VB Script
d) Visual Basic

52) What will be the output of PHP code below?

PHP Code
<?php
$arr = array(5 => 1, 12 => 2);
$arr[] = 56;
$arr["x"] = 42;
echo var_dump($arr);
?>

a) 42
b) array(3) { [12]=> int(2) [13]=> int(56) ["x"]=> int(42) }
c) array(4) { [5]=>int(1) [12]=> int(2) [13]=> int(56) ["x"]=> int(42) }
d) 1,2,56,42

53) What will the ouptut of date() function in PHP code below?

PHP Code
<?php
$date="2009-5-19";
$time="14:31:38";
$datetime=$date.$time;
echo date("Y-m-d:H:i:s",strtotime($datetime));
?>

a) 2009-5-19:14:31:38
b) 2009-5-19:2:31:38
c) 19-5-2009:2:31:38
d) 19/5/2009:14:31:38

54) What will be the output of PHP code below?

PHP Code
<?php
$color=array("red","yellow","white");
$x=in_array("black",$color);
if($x==0)
echo "good bye";
if($x==1) echo "Hello";
?>

a) Hello
b) Error
c) good bye
d) None of the above

PHP Quiz Answers

(1) a
(2) a
(3) c
(4) b
(5) a
(6) b
(7) b
(8) a
(9) a
(10) b
(11) b
(12) a
(13) b
(14) c
(15) b
(16) c
(17) a
(18) d
(19) c
(20) a
(21) c
(22) a
(23) b
(24) a
(25) a
(26) c
(27) b
(28) b
(29) b
(30) c
(31) d
(32) c
(33) b
(34) b
(35) a
(36) c
(37) c
(38) c
(39) b
(40) d
(41) a
(42) b
(43) a
(44) d
(45) d
(46) a
(47) a
(48) b
(49) a
(50) b
(51) a
(52) c
(53) a
(54) c

Attached Files
There are no attachments for this article.
Comments (1)
Comment by shailendra on Wed, Jun 23rd, 2010 at 1:35 PM
I am sorry to say but the answer of the first question which is given a is incorrect.The right answer is "c".
Name
Email
Security Code Security Code
Related Articles RSS Feed
Free 3D Flash Image Slider - Piecemaker
Viewed 1197 times since Sun, Apr 4, 2010
8 Basics of Regular Expressions
Viewed 698 times since Mon, Mar 8, 2010
Before and After Picture - jQuery Plugin
Viewed 918 times since Tue, Dec 29, 2009
Create Full Screen Slideshows With Supersized
Viewed 672 times since Tue, Jan 5, 2010
ValidForm Builder - Creating Forms With Validation
Viewed 622 times since Wed, Apr 21, 2010
Making A Basic PHP Template System
Viewed 582 times since Tue, Dec 8, 2009
jQuery MultiSelect Plugin with ThemeRoller Support
Viewed 918 times since Thu, Feb 4, 2010
OpenCart - Open Source Shopping Cart
Viewed 914 times since Fri, Jan 1, 2010
dygraphs JS Charts - Free JavaScript Charts
Viewed 652 times since Sun, Dec 13, 2009
MENU