Home

1000+ Php Programming Multiple Choice Question Answer [Solved]

Thursday 9th of March 2023

Sharing is caring

1. What will be the output of the following PHP code ?
 <?php  $i = 0;
while (++$i && --$i){ print $i;
} ?>

A. 1234567891011121314….infinitely
B. 01234567891011121314…infinitely
C. no output
D. error
Answer : C
2. Neglecting to set which of the following cookie will result in the cookies domain being set to the host name of the server which generated it.
A.
session.domain

B.
session.path

C.
session.cookie_path

D.
session.cookie_domain

Answer : D
3. What will be the output of the following PHP code ?
 <?php  $i = 2;
while (++$i){ while (--$i > 0) print $i;
} ?>

A. 210
B. 10
C. no output
D. infinite loop
Answer : D
4. Which one of the following function is used to start a session?
A.
start_session()

B.
session_start()

C.
session_begin()

D.
begin_session()

Answer : B
5.

What will be the output of the following code?



<?php
$foo = 'Bob';
$bar = &$foo;
$bar = "My name is $bar";
echo $bar;
echo $foo;
?>


A.

Error


B.

My name is BobBob


C.

My name is BobMy name is Bob


D.

My name is Bob Bob


Answer : C
6. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = green;
echo $color1.$color2;
?>

A. red green
B. red
C. green
D. error
Answer : D
7. What will be the output of the following PHP code?
 <?php  $a1 = array_fill(3, 4, blue);
$b1 = array_fill(0, 1, red);
print_r($a1);
echo
;
print_r($b1);
?>

A.
Array ( [3] => blue [4] => blue) 
Array ( [0] => red )

B.
Array ( [4] => blue [5] => blue [6] => blue) 
Array ( [0] => red )

C.
Array ( [3] => blue [4] => blue [5] => blue [6] => blue ) 
Array ()

D.
Array ( [3] => blue [4] => blue [5] => blue [6] => blue ) 
Array ( [0] => red )

Answer : D
8. What will be the output of the following PHP code ?
 <?php  $i = 2;
while (++$i){ while ($i --> 0) print $i;
} ?>

A. 210
B. 10
C. no output
D. infinite loop
Answer : A
9. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = red;
echo $color1 + $color2;
?>

A. redgreen
B. red green
C. 0
D. 1
Answer : C
10.

What does PHP stand for?


i) Personal Home Page
ii) Hypertext Preprocessor
iii) Pretext Hypertext Processor
iv) Preprocessor Home Page



A.

Both i) and iii)


B.

Both ii) and iv)


C.

Only ii)


D.

Both i) and ii)


Answer : D
11. What will be the output of the following PHP code ?
 <?php  define(__LINE__, PHP is a scripting language);
echo __LINE__;
?>

A. PHP is a scripting language
B. __LINE__
C. 2
D. ERROR
Answer : C
12. What will be the output of the following PHP code ?
 <?php  $i = 0;
while(++$i || --$i){ print $i;
} ?>

A. 1234567891011121314….infinitely
B. 01234567891011121314…infinitely
C. 1
D. 0
Answer : A
13. What will be the output of the following PHP code ?
 <?php  define('GREETING_TEST', 'PHP is a scripting language', true);
echo GREETING_TESt;
$changing_variable = 'test';
echo constant('GREETING_' . strtoupper($changing_variable));
?>

A. PHP is a scripting language
PHP is a scripting language
B. GREETING_TESt
C. PHP is a scripting language
D. PHP is a scripting language
GREETING_TEST
Answer : A
14. What will be the output of the following PHP code ?
 <?php  define(GREETING, PHP is a scripting language);
echo $GREETING;
?>

A. $GREETING
B. no output
C. PHP is a scripting language
D. GREETING
Answer : B
15. What will be the output of the following PHP code?
 <?php  $a = array(A, Cat, Dog, A, Dog);
print_r(array_count_values($a));
?>

A.
Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )

B.
Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )

C.
Array ( [A] => 1 [Cat] => 1 [Dog] => 2 )

D.
Array ( [A] => 2 [Cat] => 1 [Dog] => 1)

Answer : A
16. What is the default time(in seconds) for which session data is considered valid?
A. 1800
B. 3600
C. 1440
D. 1540
Answer : C
17. What will be the output of the following PHP code ?
 <?php  define(NEW_GOOD_NAME_CONSTANT, I have a value);
define(OLD_BAD_NAME_CONSTANT, NEW_GOOD_NAME_CONSTANT);
�echo NEW_GOOD_NAME_CONSTANT;
echo OLD_BAD_NAME_CONSTANT;
?>

A. I have a value
B. I have a valueI have a value
C. ERROR
D. I have a valueNEW_GOO_NAME_CONSTANTS
Answer : B
18. What will be the outpt of the following PHP code ?
 <?php  class Constants{    define('MIN_VALUE', '0.0');
define('MAX_VALUE', '1.0');
public static function getMinValue() { return self::MIN_VALUE;
} public static function getMaxValue() { return self::MAX_VALUE;
}}echo Constants::getMinValue();
echo Constants::getMaxValue();
?>

A. 0.01.0
B. 01
C. No output
D. ERROR
Answer : D
19. What will be the output of the following PHP code ?
 <?php  $color1 = 1;
$color2 = 1;
echo $color1 + $color2;
?>

A. 11
B. 2
C. 0
D. 1
Answer : B
20. What will be the output of the following PHP code ?
 <?php  /*echo Hello world;
*/ ?>

A. Hello world
B. Nothing
C. Error
D.
/* Hello world */

Answer : B
21. Which directive determines how the session information will be stored?
A.
save_data

B.
session.save

C.
session.save_data

D.
session.save_handler

Answer : D
22. What will be the output of the following PHP code ?
 <?php  $i = 5;
while (--$i > 0){ $i++;
print $i;
print hello;
} ?>

A. 4hello4hello4hello4hello4hello…..infinite
B. 5hello5hello5hello5hello5hello…..infinite
C. no output
D. error
Answer : A
23. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = green;
echo $color1 + $color2;
?>

A. redgreen
B. red green
C. 0
D. error
Answer : C
24.

A PHP script should start with ___ and end with ___:



A.

< php >


B.

< ? php ?>


C.

<?php ?>


D.

<% %>


Answer : C
25. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = 1;
$color3 = greyecho $color1 + $color2 . $color3;
?>

A. 1grey
B. grey
C. 0
D. red1grey
Answer : A
26. If the directive session.cookie_lifetime is set to 3600, the cookie will live until..
A. 3600 sec
B. 3600 min
C. 3600 hrs
D. the browser is restarted
Answer : A
27.

Which of following variables can be assigned a value to it?
i) $3hello
ii) $_hello
iii) $this
iv) $This



A.

All of the mentioned


B.

Only ii)


C.

ii), iii) and iv)


D.

ii) and iv)


Answer : D
28. If session.use_cookie is set to 0, this results in use of..
A. Session
B. Cookie
C. URL rewriting
D. Nothing happens
Answer : C
29.

Which of the following is/are a PHP code editor?
i) Notepad
ii) Notepad++
iii) Adobe Dreamweaver
iv) PDT



A.

Only iv)


B.

All of the mentioned.


C.

i), ii) and iii)


D.

Only iii)


Answer : B
30. What will be the output of the following PHP code ?
 <?php  define('GOOD_OCTAL', 0700);
define('BAD_OCTAL', 0600);
print GOOD_OCTAL;
print '
';
print BAD_OCTAL;
?>

A. 448
384
B. 0700
0800
C. ERROR
D. No output
Answer : A
31. The date() function returns ___ representation of the current date and/or time.
A. Integer
B. String
C. Boolean
D. Float
Answer : B
32. What will be the output of the following PHP code?
 <?php  $cars = array(Volvo, BMW, Toyota);
echo I like . $cars[0] . , . $cars[1] . and . $cars[2] . .;
?>

A. I like Volvo BMW and Toyota.
B. I like Volvo, BMW and Toyota)
C. I like Volvo, BMW and Toyota.
D. I like. Volvo.,. BMW. and. Toyota)
Answer : B
33. What will be the output of the following PHP code ?
 <?php  $i = 5;
while (--$i > 0 && ++$i){ print $i;
} ?>

A. 5
B. 555555555…infinitely
C. 54321
D. error
Answer : B
34. What will be the output of the following PHP code ?
 <?php  $i = ;
while ($i = 10){ print hi;
}print hello;
?>

A. hello
B. infinite loop
C. hihello
D. error
Answer : B
35. Which one of the following function is useful for producing a timestamp based on a given date and time.
A.
time()

B.
mktime()

C.
mrtime()

D.
mtime()

Answer : B
36. What will be the output of the following PHP code?
 <?php   $fname = array(Peter, Ben, Joe);
$age = array(35, 37, 43);
$c = array_combine($fname, $age);
print_r($c);
?>

A.
Array ( Peter Ben Joe )

B.
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )

C.
Array ( 35 37 43 )

D.
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )

Answer : B
37. What will be the output of the following PHP code?
 <?php  $a1 = array(red, green);
$a2 = array(blue, yellow);
print_r(array_merge($a1, $a2));
?>

A.
Array ( [0] => red [1] =>green)

B.
Array ( [0] => blue [1] => yellow [2] => red [3] => green )

C.
Array ( [0] => red [1] => green [2] => blue [3] => yellow )

D.
Array ( [0] => blue [1] => yellow )

Answer : C
38.

Which of the following PHP statements will output Hello World on the screen?
i) echo (“Hello World”);
ii) print (“Hello World”);
iii) printf (“Hello World”);
iv) sprintf (“Hello World”);



A.

i) and ii)


B.

i), ii) and iii)


C.

All of the mentioned


D.

i), ii) and iv)


Answer : B
39. Say you want to calculate the date 45 days from the present date which one of the following statement will you use?
A.
totime(+45)

B.
totime(+45 days)

C.
strtotime(+45 days)

D.
strtotime(-45 days)

Answer : C
40. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = 1;
echo $color1 + $color2;
?>

A. red1
B. red 1
C. 0
D. 1
Answer : D
41. What is the default number of seconds that cached session pages are made available before the new pages are created?
A. 360
B. 180
C. 3600
D. 1800
Answer : B
42. Which one of the following format parameter can be used to identify timezone?
A. T
B. N
C. E
D. I
Answer : C
43. What will be the output of the following PHP code?
 <?php  $a = array(red, green, blue);
array_pop($a);
print_r($a);
?>

A.
Array ( [0] => red [1] => green )

B.
Array ( [0] => green [1] => blue )

C.
Array ( [0] => red [1] => blue )

D.
Array ( [0] => blue [1] => blue )

Answer : A
44. What will be the output of the following PHP code?
     <?php      echo (checkdate(4,31,2010) ? 'Valid' : 'Invalid');
?>

A. TRUE
B. FALSE
C. Valid
D. Invalid
Answer : D
45. What will be the output of the following PHP code ?
 <?php  class myObject { }define('myObject::CONSTANT', 'test');
echo myObject::CONSTANT;
?>

A. test
B. error
C. myObject::CONSTANT
D. no output
Answer : B
46. To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?
A.
$date = Date(22 JUNE 2013)

B.
$date = new Date(JUNE 22 2013)

C.
$date = DateTime(22 JUNE 2013)

D.
$date = new DateTime(22 JUNE 2013)

Answer : D
47. What will be the output of the following PHP code?
 <?php  $a1 = array(a=>red, b=>green, c=>blue, d=>yellow);
$a2 = array(e=>red, f=>green, g=>blue);
$result = array_diff($a1, $a2);
print_r($result);
?>

A.
Array ( [d] => yellow )

B.
Array ( [c] => blue )

C.
Array ( [a] => red )

D.
Array ( [e] => yellow )

Answer : A
48. What will be the output of the following PHP code ?
 <?php  $i = 0;
while ($i = 10){ print hi;
}print hello;
?>

A. hello
B. infinite loop
C. hihello
D. error
Answer : B
49. What will be the output of the following PHP code ?
 <?php  $i = 0;
while ((--$i > ++$i) - 1){ print $i;
} ?>

A. 00000000000000000000….infinitely
B. -1-1-1-1-1-1-1-1-1-1…infinitely
C. no output
D. error
Answer : A
50. 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 : C

Sharing is caring