Saturday, February 13, 2021

PHP Programming new 68 Solved Mcq Question Answer

Question: 1.

What does PHP stand for?


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


Option A.

Both i) and iii)


Option B.

Both ii) and iv)


Option C.

Only ii)


Option D.

Both i) and ii)



Question: 2.

PHP files have a default file extension of..


Option A.

.html


Option B.

.xml


Option C.

.php


Option D.

.ph


Option E.

.asp


Option F.

.jsp



Question: 3.

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


Option A.

< php >


Option B.

< ? php ?>


Option C.

<?php ?>


Option D.

<% %>



Question: 4.

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


Option A.

Only iv)


Option B.

All of the mentioned.


Option C.

i), ii) and iii)


Option D.

Only iii)



Question: 5.

Which of the following must be installed on your computer so as to run PHP script?
i) Adobe Dreamweaver
ii) PHP
iii) Apache
iv) IIS


Option A.

All of the mentioned.


Option B.

Only ii)


Option C.

ii) and iii)


Option D.

ii), iii) and iv)



Question: 6.

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


Option A.

All of the mentioned


Option B.

Only ii)


Option C.

ii), iii) and iv)


Option D.

ii) and iv)



Question: 7.

What will be the output of the following code?



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

Option A.

Error


Option B.

My name is BobBob


Option C.

My name is BobMy name is Bob


Option D.

My name is Bob Bob



Question: 8.

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”);


Option A.

i) and ii)


Option B.

i), ii) and iii)


Option C.

All of the mentioned


Option D.

i), ii) and iv)



Question: 9. What will be the output of the following PHP code ?
 <?php  $i = 0;
while ((--$i > ++$i) - 1){ print $i;
} ?>
Option A. 00000000000000000000….infinitely
Option B. -1-1-1-1-1-1-1-1-1-1…infinitely
Option C. no output
Option D. error

Question: 10. What will be the output of the following PHP code ?
 <?php  $color = red;
echo $color . red ;
?>
Option A. red red
Option B. red
Option C. error
Option D. nothing

Question: 11. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = red;
echo $color1 + $color2;
?>
Option A. redgreen
Option B. red green
Option C. 0
Option D. 1

Question: 12. 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;
?>
Option A. 448
384
Option B. 0700
0800
Option C. ERROR
Option D. No output

Question: 13. 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));
?>
Option A.
Array ( [0] => red [1] => green)
Option B.
Array ( [0] => blue [1] => yellow [2] => red [3] => green )
Option C.
Array ( [0] => red [1] => green [2] => blue [3] => yellow )
Option D.
Array ( [0] => blue [1] => yellow )

Question: 14. Which one of the following function is used to start a session?
Option A.
start_session()
Option B.
session_start()
Option C.
session_begin()
Option D.
begin_session()

Question: 15. 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);
?>
Option A.
Array ( [3] => blue [4] => blue) 
Array ( [0] => red )
Option B.
Array ( [4] => blue [5] => blue [6] => blue) 
Array ( [0] => red )
Option C.
Array ( [3] => blue [4] => blue [5] => blue [6] => blue ) 
Array ()
Option D.
Array ( [3] => blue [4] => blue [5] => blue [6] => blue ) 
Array ( [0] => red )

Question: 16. What will be the output of the following PHP code ?
 <?php  $i = ;
while ($i = 10){ print hi;
}print hello;
?>
Option A. hello
Option B. infinite loop
Option C. hihello
Option D. error

Question: 17. 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);
?>
Option A.
Array ( [d] => yellow )
Option B.
Array ( [c] => blue )
Option C.
Array ( [a] => red )
Option D.
Array ( [e] => yellow )

Question: 18. What will be the output of the following PHP code ?
 <?php  define(VAR_NAME,test);
${VAR_NAME} = value;
echo VAR_NAME;
echo ${VAR_NAME};
?>
Option A. test
Option B. testtest
Option C. testvalue
Option D. error, constant value cannot be changed

Question: 19. Which one of the following is the default PHP session name?
Option A. PHPSESSID
Option B. PHPSESID
Option C. PHPSESSIONID
Option D. PHPIDSESS

Question: 20. Which one of the following is the very first task executed by a session enabled page?
Option A. Delete the previous session
Option B. Start a new session
Option C. Check whether a valid session exists
Option D. Handle the session

Question: 21. What will be the output of the following PHP code ?
 <?php  $i = 5;
while (--$i > 0 && ++$i){ print $i;
} ?>
Option A. 5
Option B. 555555555…infinitely
Option C. 54321
Option D. error

Question: 22. What will be the output of the following PHP code ?
 <?php  $color = red;
$color = green;
echo $color;
?>
Option A. red
Option B. green
Option C. red green
Option D. error

Question: 23. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = green;
echo $color1 . $color2;
?>
Option A. red
Option B. green
Option C. red green
Option D. redgreen

Question: 24. What will be the output of the following PHP code?
 <?php  $a = array(a=>red, b=>green, c=>blue);
echo array_shift($a);
print_r ($a);
?>
Option A.
green
Option B.
red
Option C.
redArray( [c] => green [c] => blue )
Option D.
redArray( [b] => green [c] => blue )

Question: 25. How many ways can a session data be stored?
Option A. 3
Option B. 4
Option C. 5
Option D. 6

Question: 26. What will be the output of the following PHP code ?
 <?php  define('IF', 42);
echo IF: , IF;
?>
Option A. IF:42
Option B. No output
Option C. IF:
Option D. ERROR

Question: 27. Which one of the following format parameter can be used to identify timezone?
Option A. T
Option B. N
Option C. E
Option D. I

Question: 28. What will be the output of the following PHP code?
 <?php  $a = array(A, Cat, Dog, A, Dog);
print_r(array_count_values($a));
?>
Option A.
Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
Option B.
Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )
Option C.
Array ( [A] => 1 [Cat] => 1 [Dog] => 2 )
Option D.
Array ( [A] => 2 [Cat] => 1 [Dog] => 1)

Question: 29. Which one of the following function is useful for producing a timestamp based on a given date and time.
Option A.
time()
Option B.
mktime()
Option C.
mrtime()
Option D.
mtime()

Question: 30. What will be the output of the following PHP code?
 <?php  $a = array(red, green, blue);
array_pop($a);
print_r($a);
?>
Option A.
Array ( [0] => red [1] => green )
Option B.
Array ( [0] => green [1] => blue )
Option C.
Array ( [0] => red [1] => blue )
Option D.
Array ( [0] => blue [1] => blue )

Question: 31. What will be the output of the following PHP code ?
 <?php  /*echo Hello world;
*/ ?>
Option A. Hello world
Option B. Nothing
Option C. Error
Option D.
/* Hello world */

Question: 32. What will be the output of the following PHP code? If say date is 22/06/2013.
     <?php      printf( date(t) )     ?> 
Option A. 30
Option B. 22
Option C. JUNE
Option D. 2013

Question: 33. 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);
?>
Option A.
Array ( Peter Ben Joe )
Option B.
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
Option C.
Array ( 35 37 43 )
Option D.
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )

Question: 34. Say you want to calculate the date 45 days from the present date which one of the following statement will you use?
Option A.
totime(+45)
Option B.
totime(+45 days)
Option C.
strtotime(+45 days)
Option D.
strtotime(-45 days)

Question: 35. What will be the output of the following PHP code?
     <?php      echo (checkdate(4,31,2010) ? 'Valid' : 'Invalid');
?>
Option A. TRUE
Option B. FALSE
Option C. Valid
Option D. Invalid

Question: 36. What will be the output of the following PHP code ?
 <?php  define(__LINE__, PHP is a scripting language);
echo __LINE__;
?>
Option A. PHP is a scripting language
Option B. __LINE__
Option C. 2
Option D. ERROR

Question: 37. What will be the output 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();
?>
Option A. 0.01.0
Option B. 01
Option C. No output
Option D. ERROR

Question: 38. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = green;
echo $color1 + $color2;
?>
Option A. redgreen
Option B. red green
Option C. 0
Option D. error

Question: 39. What will be the output of the following PHP code?
 <?php  $age = array(Peter=>35, Ben=>37, Joe=>43);
print_r(array_change_key_case($age, CASE_UPPER));
?>
Option A.
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
Option B.
Array ( [peter] => 35 [ben] => 37 [joe] => 43 )
Option C.
Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
Option D.
Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )

Question: 40. What will be the output of the following PHP code ?
 <?php  $i = 0;
while ($i = 10){ print hi;
}print hello;
?>
Option A. hello
Option B. infinite loop
Option C. hihello
Option D. error

Question: 41. What will be the output of the following PHP code ?
 <?php  define(GREETING, PHP is a scripting language);
echo $GREETING;
?>
Option A. $GREETING
Option B. no output
Option C. PHP is a scripting language
Option D. GREETING

Question: 42. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = green;
echo $color1.$color2;
?>
Option A. red green
Option B. red
Option C. green
Option D. error

Question: 43. What will be the output of the following PHP code ?
 <?php  $i = 2;
while (++$i){ while (--$i > 0) print $i;
} ?>
Option A. 210
Option B. 10
Option C. no output
Option D. infinite loop

Question: 44. Which function displays the web pages most recent modification date?
Option A.
lastmod()
Option B.
getlastmod()
Option C.
last_mod()
Option D.
get_last_mod()

Question: 45. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = 1;
echo $color1 + $color2;
?>
Option A. red1
Option B. red 1
Option C. 0
Option D. 1

Question: 46. What will be the output of the following PHP code ?
 <?php  $i = 5;
while (--$i > 0 || ++$i){ print $i;
} ?>
Option A. 54321111111….infinitely
Option B. 555555555…infinitely
Option C. 54321
Option D. 5

Question: 47. What is the default number of seconds that cached session pages are made available before the new pages are created?
Option A. 360
Option B. 180
Option C. 3600
Option D. 1800

Question: 48. 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));
?>
Option A. PHP is a scripting language
PHP is a scripting language
Option B. GREETING_TESt
Option C. PHP is a scripting language
Option D. PHP is a scripting language
GREETING_TEST

Question: 49. If the directive session.cookie_lifetime is set to 3600, the cookie will live until..
Option A. 3600 sec
Option B. 3600 min
Option C. 3600 hrs
Option D. the browser is restarted

Question: 50. 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;
?>
Option A. I have a value
Option B. I have a valueI have a value
Option C. ERROR
Option D. I have a valueNEW_GOO_NAME_CONSTANTS

Question: 51. What will be the output of the following PHP code ?
 <?php  $i = 0;
while (++$i && --$i){ print $i;
} ?>
Option A. 1234567891011121314….infinitely
Option B. 01234567891011121314…infinitely
Option C. no output
Option D. error

Question: 52. 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] . .;
?>
Option A. I like Volvo BMW and Toyota.
Option B. I like Volvo, BMW and Toyota)
Option C. I like Volvo, BMW and Toyota.
Option D. I like. Volvo.,. BMW. and. Toyota)

Question: 53. What will be the output of the following PHP code ?
 <?php  define(GREETING, PHP is a scripting language, true);
echo GREETING;
echo
echo GREETING;
?>
Option A. PHP is a scripting language
Option B. GREETING
GREEtING
Option C. GREETING
Option D. PHP is a scripting language
PHP is a scripting language

Question: 54. To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?
Option A.
$date = Date(22 JUNE 2013)
Option B.
$date = new Date(JUNE 22 2013)
Option C.
$date = DateTime(22 JUNE 2013)
Option D.
$date = new DateTime(22 JUNE 2013)

Question: 55. If the format is F then which one of the following will be returned?
Option A. Complete text representation of month
Option B. Day of month, with leading zero
Option C. Daylight saving time
Option D. Day of month, without zeros

Question: 56. 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.
Option A.
session.domain
Option B.
session.path
Option C.
session.cookie_path
Option D.
session.cookie_domain

Question: 57. What will be the output of the following PHP code ?
 <?php  $i = 0;
while(++$i || --$i){ print $i;
} ?>
Option A. 1234567891011121314….infinitely
Option B. 01234567891011121314…infinitely
Option C. 1
Option D. 0

Question: 58. What will be the output of the following PHP code ?
 <?php  class myObject { }define('myObject::CONSTANT', 'test');
echo myObject::CONSTANT;
?>
Option A. test
Option B. error
Option C. myObject::CONSTANT
Option D. no output

Question: 59. What is the default time(in seconds) for which session data is considered valid?
Option A. 1800
Option B. 3600
Option C. 1440
Option D. 1540

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

Question: 61. Which directive determines how the session information will be stored?
Option A.
save_data
Option B.
session.save
Option C.
session.save_data
Option D.
session.save_handler

Question: 62. What will be the output of the following PHP code ?
 <?php  $i = 5;
while (--$i > 0){ $i++;
print $i;
print hello;
} ?>
Option A. 4hello4hello4hello4hello4hello…..infinite
Option B. 5hello5hello5hello5hello5hello…..infinite
Option C. no output
Option D. error

Question: 63. What will be the output of the following PHP code ?
 <?php  $color1 = 1;
$color2 = 1;
echo $color1 + $color2;
?>
Option A. 11
Option B. 2
Option C. 0
Option D. 1

Question: 64. What will be the output of the following code? If say date is 22/06/2013.
     <?php      echo Today is .date(F d, Y)     ?> 
Option A. Today is 22 June, 2013
Option B. Today is 22-06-2013
Option C. Today is 06-22-2013
Option D. Today is June 22, 2013

Question: 65. What will be the output of the following PHP code?
 <?php  $cars = array(Volvo, BMW, Toyota, Honda, Mercedes, Opel);
print_r(array_chunk($cars, 2));
?>
Option A.
Array ( [0] => Array ( [1] => Volvo [2] => BMW ) [1] => Array ( [1] => Toyota [2] => Honda ) [2] => Array ( [1] => Mercedes [2] => Opel ) )
Option B.
Array ( [1] => Array ( [1] => Volvo [2] => BMW ) [2] => Array ( [1] => Toyota [2] => Honda ) [3] => Array ( [1] => Mercedes [2] => Opel ) )
Option C.
Array ( [0] => Array ( [0] => Volvo [1] => Volvo ) [1] => Array ( [0] => BMW [1] => BMW ) [2] => Array ( [0] => Toyota [1] => Toyota ) )
Option D.
Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )

Question: 66. What will be the output of the following PHP code ?
 <?php  $i = 2;
while (++$i){ while ($i --> 0) print $i;
} ?>
Option A. 210
Option B. 10
Option C. no output
Option D. infinite loop

Question: 67. The date() function returns ___ representation of the current date and/or time.
Option A. Integer
Option B. String
Option C. Boolean
Option D. Float

Question: 68. What will be the output of the following PHP code ?
 <?php  $color1 = red;
$color2 = 1;
$color3 = greyecho $color1 + $color2 . $color3;
?>
Option A. 1grey
Option B. grey
Option C. 0
Option D. red1grey

Answer Sheet

1D

PHP previously stood for Personal Home Page now stands for Hypertext Preprocessor.


2C
3C

Every section of PHP code starts and ends by turning on and off PHP tags to let the server know that it needs to execute the PHP in between them.


4B

Any of the above editors can be used to type php code and run it.


5D

To run PHP code you need to have PHP and a web server, both IIS and Apache are web servers.You can choose either one according to your platform.


6D

A variable can’t start with a number. Also $this is a special variable that can’t be assigned, but $This can be assigned


7C

The $bar = &$foo; line will reference $foo via $bar.


8B

echo(), print() and printf() all three can be used to output a statement onto the screen. The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser.


9A($i > ++$i) evaluates to 0 but -1 makes it enters the loop and prints i which is 0.
10CUse of undefined constant red.
11C+ does not return 1 if the variables are equal.
12AAnything starting from 0 is evaluated as an octal.
13CThe array_merge() function merges one or more arrays into one array.
14B
15DThe array_fill() function fills an array with values.
16BWhile condition always gives 1.
17AThe array_diff() function compares the values of two (or more) arrays, and returns the differences.
18C
${VAR_NAME}
creates a new variable which is not same as VAR_NAME.
19AYou can change this name by using the session.name directive.
20C
21BAs it is && operator it is being incremented and decremented continuously.
22BThe variable contains the last value which has been assigned.
23DThe . operator is used to join to strings.
24DThe array_shift() function removes the first element from an array, and returns the value of the removed element.
25BWithin flat files(files), within volatile memory(mm), using the SQLite database(sqlite), or through user defined functions(user).
26DKeyword like IF cannot be used as constant names.
27CWhen the format is E the timezone is identified and returned…example America/New_York.
28AThe array_count_values() function counts all the values of an array.
29B
30AThe array_pop() function deletes the last element of an array.
31B/* */ is used for commenting multiple lines.
32AThe t parameter is used to determine the number of days in the current month.
33BThe array_combine() function creates an array by using the elements from one keys array and one values array.
34CThe
strtotime()
function and GNU date syntax is used to calculating the date x days from the present date.
35DApril has 30 days and the above date is 31 therefore Invalid is returned.
36C__LINE__ is a magical constant that gives the current line number and cannot be used a variable/constant name.
37DIn a class constants should be defined const MIN_VALUE = 0.0;
const MAX_VALUE = 1.0;
instead.
38C+ operator does not join both the strings.
39CThe array_change_key_case() function changes all keys in an array to lowercase or uppercase.
40BWhile condition always gives 1.
41BConstants do not need a $ before them, they are referenced by their variable names itself.
42DIt has to be $color1 = red;
and $color2 = green;
therefore the error.
43DThe loop never ends as i is always incremented and then decremented.
44BThe getlastmod() function returns the value of the pages Last Modified header or FALSE in the case of an error.
45D+ just returns the numeric value even though it is inside double quotes.
46AAs it is || operator the second expression is not evaluated till i becomes 1 then it goes into a loop.
47BThe directive which determines this is session.cache_expire.
48Aecho constant(x) output x, and x here is the concatenation of GREETING_ and $changing variable with. operator.
49AThe lifetime is specified in seconds, so if the cookie should live 1 hour, this directive should be set to 3600.
50BConstants can be set as values for other constants.
51CThe first condition itself fails thus the loop exits.
52BThe array() function is used to create an array. Each elements are assigned ab index as the rule of an array. So, calling $cars[0] will print element at index 0 and so on.
53DSince the third parameter is true in define(GREETING, PHP is a scripting language, true) is true GREETING becomes case insensitive.
54DThe
dateTime()
method is class constructor. You can set the date either at the time of instantiation or later by using a variety of mutators.
55ADay of month, with leading zero is represented by D;
Daylight saving time by I;
Day of month, without zeros by j.
56DThe directive
session.cookie_domain
determines the domain for which the cookie is valid.
57AAs it is || operator the second expression is not evaluated and i is always incremented, in the first case to 1.
58BClass constants cannot be defined outside class.
59CThe
session.gc_maxlifetime
directive determines this duration. It can be set to any required value.
60C
61DIts prototype follows: session.save_handler = files|mm|sqlite|user.
62Ai is decremented in the first while execution and then continuously incremented back.
63B+ can be used to add to integer values which are enclosed by double-quotes.
64DF is the parameter for complete text representation of month, d for day of month, and Y for 4 digit representation of year.
65DThe array_chunk() function splits an array into chunks of new arrays.
66AThe loop ends when i becomes 0.
67BThe prototype of this function is: string date(string format [, int timestamp]).
68A+ gives the value 1 and . is used to give join 1 and grey.

0 comments:

Post a Comment