Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

PHP MCQ Set 1

1. What will be the output of the following PHP code ?

  1. <?php
  2. define("GREETING", "PHP is a scripting language", true);
  3. echo GREETING;
  4. echo "<br>"
  5. echo GREETING;
  6. ?>

a) PHP is a scripting language
b) GREETING
GREEtING
c) GREETING
d) PHP is a scripting language
PHP is a scripting language

View Answer

Answer: d [Reason:] Since the third parameter is true in define(“GREETING”, “PHP is a scripting language”, true) is true GREETING becomes case insensitive.

2. What will be the output of the following PHP code ?

  1. <?php
  2. define("GREETING", "PHP is a scripting language");
  3. echo $GREETING;
  4. ?>

a) $GREETING
b) no output
c) PHP is a scripting language
d) GREETING

View Answer

Answer: b [Reason:] Constants do not need a $ before them, they are referenced by their variable names itself.

3. What will be the output of the following PHP code ?

  1. <?php
  2. define('GREETING_TEST', 'PHP is a scripting language', true);
  3. echo GREETING_TESt;
  4. $changing_variable = 'test';
  5. echo constant('GREETING_' . strtoupper($changing_variable));
  6. ?>

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

View Answer

Answer: a [Reason:] echo constant(x) output x, and x here is the concatenation of GREETING_ and $changing variable with. operator.

4. What will be the output of the following PHP code ?

  1. <?php
  2. class Constants
  3. {
  4.     define('MIN_VALUE', '0.0');  
  5.     define('MAX_VALUE', '1.0');  
  6.     public static function getMinValue()
  7.     {
  8.         return self::MIN_VALUE;
  9.     }
  10.     public static function getMaxValue()
  11.     {
  12.         return self::MAX_VALUE;
  13.     }
  14. }
  15. echo Constants::getMinValue();
  16. echo Constants::getMaxValue();
  17. ?>

a) 0.01.0
b) 01
c) No output
d) ERROR

View Answer

Answer: d [Reason:] In a class constants should be defined const MIN_VALUE = 0.0;const MAX_VALUE = 1.0; instead.

5. What will be the output of the following PHP code ?

  1. <?php
  2. define("__LINE__", "PHP is a scripting language");
  3. echo __LINE__;
  4. ?>

a) PHP is a scripting language
b) __LINE__
c) 2
d) ERROR

View Answer

Answer: c [Reason:] __LINE__ is a magical constant that gives the current line number and cannot be used a variable/constant name.

6. What will be the output of the following PHP code ?

  1. <?php
  2. define('IF', 42); 
  3. echo "IF: ", IF;
  4. ?>

a) IF:42
b) No output
c) IF:
d) ERROR

View Answer

Answer: d [Reason:] Keyword like IF cannot be used as constant names.

7. What will be the output of the following PHP code ?

  1. <?php
  2. define("NEW_GOOD_NAME_CONSTANT", "I have a value");
  3. define("OLD_BAD_NAME_CONSTANT", NEW_GOOD_NAME_CONSTANT);
  4.  
  5. echo NEW_GOOD_NAME_CONSTANT;
  6. echo OLD_BAD_NAME_CONSTANT; 
  7. ?>

a) I have a value
b) I have a valueI have a value
c) ERROR
d) I have a valueNEW_GOO_NAME_CONSTANTS

View Answer

Answer: b [Reason:] Constants can be set as values for other constants.

8. What will be the output of the following PHP code ?

  1. <?php
  2. define('GOOD_OCTAL', 0700);
  3. define('BAD_OCTAL', 0600);
  4. print GOOD_OCTAL;
  5. print '<br>';
  6. print BAD_OCTAL; 
  7. ?>

a) 448
384
b) 0700
0800
c) ERROR
d) No output

View Answer

Answer: a [Reason:] Anything starting from 0 is evaluated as an octal.

9. What will be the output of the following PHP code ?

  1. <?php
  2. define("VAR_NAME","test"); 
  3. ${VAR_NAME} = "value"; 
  4. echo VAR_NAME;
  5. echo ${VAR_NAME}; 
  6. ?>

a) test
b) testtest
c) testvalue
d) error, constant value cannot be changed

View Answer

Answer: c [Reason:] ${VAR_NAME} creates a new variable which is not same as VAR_NAME.

10. What will be the output of the following PHP code ?

  1. <?php
  2. class myObject { }
  3. define('myObject::CONSTANT', 'test');
  4. echo myObject::CONSTANT; 
  5. ?>

a) test
b) error
c) myObject::CONSTANT
d) no output

View Answer

Answer: b [Reason:] Class constants cannot be defined outside class.

PHP MCQ Set 2

1. What will be the output of the following PHP code ?

  1. <?php
  2. $a = "1";
  3. switch ($a)
  4. {
  5. case 1:
  6.     print "hi";
  7. case 2:
  8.     print "hello";
  9. default:
  10.     print "hi1";
  11. }
  12. ?>

a) hihellohi1
b) hi
c) hihi1
d) hi1

View Answer

Answer: a [Reason:] As break is not provided it executes all the cases.

2. What will be the output of the following PHP code ?

  1. <?php
  2. $a = "2";
  3. switch ($a)
  4. {
  5. case 1:
  6.     print "hi";
  7. case 2:
  8.     print "hello";
  9.     break;
  10. default:
  11.     print "hi1";
  12. }
  13. ?>

a) hihellohi1
b) hello
c) hihi1
d) hi1

View Answer

Answer: b [Reason:] As hello is provided after case2 it breaks the loop.

3. What will be the output of the following PHP code ?

  1. <?php
  2. $a = "1";
  3. switch($a)
  4. {
  5. case 1:
  6.     break;
  7.     print "hi";
  8. case 2:
  9.     print "hello";
  10.     break;
  11. default:
  12.     print "hi1";
  13. }
  14. ?>

a) hihellohi1
b) no output
c) hihi1
d) hi1

View Answer

Answer: b [Reason:] As break is provided before print statement in case 2 it breaks the loop before printing.

4. What will be the output of the following PHP code ?

  1. <?php
  2. $a = "1";
  3. $a = 1;
  4. $b = 1;
  5. switch($a)
  6. {
  7. case $a * $b: 
  8.     print "hi";
  9.     break;
  10. case $a / $b:
  11.     print "hello";
  12.     break;
  13. default:
  14.     print "hi1";
  15. }
  16. ?>

a) hihellohi1
b) hi
c) hihello
d) hi1

View Answer

Answer: b [Reason:] It checks the first case, when it finds it equal it will perform it breaks out.

5. What will be the output of the following PHP code ?

  1. <?php
  2. $a = 97;
  3. switch($a)
  4. {
  5. case "a":
  6.     print "hi";
  7.     break;
  8. case 97:
  9.     print "hello";
  10.     break;
  11. default:
  12.     print "hi1";
  13. }
  14. ?>

a) hihellohi1
b) hi
c) hihello
d) hello

View Answer

Answer: d [Reason:] Downcasting does not happen in case,it compares only with its data type.

6. What will be the output of the following PHP code ?

  1. <?php
  2. $b = 1;
  3. switch($b)
  4. {
  5. case 1.0:
  6.     print "hi";
  7.     break;
  8. case 1:
  9.     print "hello";
  10.     break;
  11. default:
  12.     print "hi1";
  13. }
  14. ?>

a) hihellohi1
b) hi
c) hihello
d) hello

View Answer

Answer: a [Reason:] Upcasting does happen in case,it compares it with 1.0 and thus prints hi and exits.

7. What will be the output of the following PHP code ?

  1. <?php
  2. const $b = 1;
  3. switch($b)
  4. {
  5. case 1:
  6.     print "hi";
  7.     break;
  8. case 1:
  9.     print "hello";
  10.     break;
  11. default:
  12.     print "hi1";
  13. }
  14. ?>

a) error
b) hi
c) hihello
d) hello

View Answer

Answer: a [Reason:] Constants cannot be used in switch cases.

8. What will be the output of the following PHP code ?

  1. <?php
  2. $b = 1;
  3. switch(print $b)
  4. {
  5. case 2:
  6.     print "hello";
  7.     break;
  8. case 1:
  9.     print "hi";
  10.     break;
  11. default:
  12.     print "hi1";
  13. }
  14. ?>

a) 1hello
b) 1hi
c) 1hi1
d) error

View Answer

Answer: b [Reason:] Print returns 1,thus it gives case 1.

9. What will be the output of the following PHP code ?

  1. <?php
  2. switch($b)
  3. {
  4. case 2:
  5.     print "hello";
  6.     break;
  7. case 1:
  8.     print "hi";
  9.     break;
  10. }
  11. ?>

a) hello
b) hi
c) no output
d) error

View Answer

Answer: c [Reason:] If that case does not exist then it searches for default and on not finding it does nothing.

10. What will be the output of the following PHP code ?

  1. <?php
  2. switch($b)
  3. {
  4. case 2:
  5.     print "hello";
  6.     break;
  7. case b:
  8.     print "hi";
  9.     break;
  10. }
  11. ?>

a) hello
b) hi
c) no output
d) error

View Answer

Answer: c [Reason:] Case cannot be defined by a variable.

PHP MCQ Set 3

1. What will be the output of the following PHP code ?

  1. <?php
  2. $a = 10;
  3. echo ++$a;
  4. echo $a++;
  5. echo $a;
  6. echo ++$a;
  7. ?>

a) 11111213
b) 11121213
c) 11111212
d) 11111112

View Answer

Answer: a [Reason:] ++$a increments a and then prints it,$a++ prints and then increments.

2. What will be the output of the following PHP code ?

  1. <?php
  2. $a = 12;
  3. --$a;
  4. echo $a++;
  5. ?>

a) 11
b) 12
c) 10
d) error

View Answer

Answer: a [Reason:] The + operator does union of arrays in that order, then the === operator compares key and value pairs.

3. What will be the output of the following PHP code ?

  1. <?php
  2. $x = "test";
  3. $y = "this";
  4. $z = "also"; 
  5. $x .= $y .= $z ;
  6. echo $x;
  7. echo $y;
  8. ?>

a) testthisthisalso
b) testthis
c) testthisalsothisalso
d) error at line 4

View Answer

Answer: c [Reason:] The x .= y is a shorthand for x = x.y and this is evaluated from right to left.

4. What will be the output of the following PHP code ?

  1. <?php
  2. $x = 1;
  3. $y = 2;
  4. if (++$x == $y++)
  5. {
  6.     echo "true ", $y, $x;
  7. }
  8. ?>

a) no output
b) true 23
c) true 22
d) true 33

View Answer

Answer: b [Reason:] x is preincremented and y is post incremented thus both are 2 in the if condition, later y is incremented.

5. What will be the output of the following PHP code ?

  1. <?php
  2. $y = 2;
  3. $w = 4;
  4. $y *= $w /= $y;
  5. echo $y, $w;
  6. ?>

a) 80.5
b) 44
c) 82
d) 42

View Answer

Answer: d [Reason:] Expression is evaluated from right to left.

6. What will be the output of the following PHP code ?

  1. <?php
  2. $y = 2;
  3. if ($y-- == ++$y)
  4. {
  5.     echo $y;
  6. }
  7. ?>

a) 2
b) 1
c) 3
d) no output

View Answer

Answer: a [Reason:] First $y = 2 is compared to and then decremented, then incremented and compared to $y = 2.

7. What will be the output of the following PHP code ?

  1. <?php
  2. $y = 2;
  3. if (**$y == 4)
  4. {
  5.     echo $y;
  6. }
  7. ?>

a) 4
b) 2
c) error at line2
d) no output

View Answer

Answer: c [Reason:] The ** is not a valid operator,only ++ and — exist.

8. What will be the output of the following PHP code ?

  1. <?php
  2. $y = 2;
  3. if (--$y == 2 || $y xor --$y)
  4. {
  5.     echo $y;
  6. }
  7. ?>

a) 1
b) 0
c) 2
d) no output

View Answer

Answer: b [Reason:] –$y == 2 is false but y is decremented, the xor gives true if only one of the operands are true, thus 1 xor 0 is true.

9. What will be the output of the following PHP code ?

  1. <?php
  2. $y = 2;
  3. if (--$y <> ($y != $y++))
  4. {
  5.     echo $y;
  6. }
  7. ?>

a) 1
b) 0
c) 2
d) no output

View Answer

Answer: b [Reason:] –$y == 2 is false but y is decremented, the xor gives true if only one of the operands are true, thus 1 xor 0 is true.

10. What will be the output of the following PHP code ?

  1. <?php
  2. echo $x-- != ++$x;
  3. ?>

a) 1
b) 0
c) error
d) no output

View Answer

Answer: a [Reason:] Automatically x is declared and initialized to 0,then decremented and compared with its increments, thus returns 1.

11. What will be the output of the following PHP code ?

  1. <?php
  2. $auth = 1;
  3. $status = 1;
  4. if ($result = (($auth == 1) && ($status != 0)))
  5. {
  6.     print "result is $result<br />";
  7. }
  8. ?>

a) result is true
b) result is 1
c) error
d) no output

View Answer

Answer: b [Reason:] Result is x&&y which returns 1 if both x and y are true.

PHP MCQ Set 4

1. What will be the output of the following PHP code ?

  1. <?php
  2. $i = 0;
  3. for ($i)
  4. {
  5.     print $i;
  6. }
  7. ?>

a) 0
b) infinite loop
c) no output
d) error

View Answer

Answer: d [Reason:] Wrong syntax for for loop.

2. What will be the output of the following PHP code ?

  1. <?php
  2. $colors = array("red","green","blue","yellow"); 
  3. foreach ($colors as $value)
  4. {
  5.     echo "$value <br>";
  6. }
  7. ?>

a) red
green
blue
yellow
b) red
c) no output
d) error

View Answer

Answer: a [Reason:] This runs a for loop for that array.

3. What will be the output of the following PHP code ?

  1. <?php
  2. for ($x = 0; $x <= 10; $x++)
  3. {
  4.     echo "The number is: $x <br>";
  5. }
  6. ?>

a) The number is: 0
The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5
The number is: 6
The number is: 7
The number is: 8
The number is: 9
The number is: 10
b) The number is: 0
c) no output
d) error

View Answer

Answer: a [Reason:] This runs a for loop from 0 to 10.

4. What will be the output of the following PHP code ?

  1. <?php
  2. for ($x = 0; $x <= 10; print ++$x)
  3. {
  4.     print ++$x;
  5. }
  6. ?>

a) 123456789101112
b) 12345678910
c) 1234567891011
d) infinite loop

View Answer

Answer: a [Reason:] The value of x is incremented and printed twice before checking,thus last loop it prints 11 and 12.

5. What will be the output of the following PHP code ?

  1. <?php
  2. for ($x = 1; $x < 10;++$x)
  3. {
  4.     print "*t";
  5. }
  6. ?>

a) **********
b) *********
c) ***********
d) infinite loop

View Answer

Answer: b [Reason:] Loop runs from 1 to 9 i.e 9 times.

6. What will be the output of the following PHP code ?

  1. <?php
  2. for ($x = -1; $x < 10;--$x)
  3. {
  4.     print $x;
  5. }
  6. ?>

a) 123456789101112
b) 12345678910
c) 1234567891011
d) infinite loop

View Answer

Answer: d [Reason:] The value of x is decremented thus making it an infinite loop.

7. What will be the output of the following PHP code ?

  1. <?php
  2. $x;
  3. for ($x = -3; $x < -5; ++$x)
  4. {
  5.     print ++$x;
  6. }
  7. ?>

a) -3-4-5
b) -3-4
c) infinite loop
d) no output

View Answer

Answer: d [Reason:] The loop is not even entered as x is initially 0.

8. What will be the output of the following PHP code ?

  1. <?php
  2. for ($i++; $i == 1; $i = 2)
  3.     print "In for loop ";
  4. print "After loopn";
  5.  
  6. ?>

a) In for loop
b) After for loop
c) In for loopAfter for loop
d) Infinite loop

View Answer

Answer: c [Reason:] The loop runs only once as value of x is incremented.

9. What will be the output of the following PHP code ?

  1. <?php
  2. for (1; $i == 1; $i = 2)
  3.     print "In for loop ";
  4. print "After loopn";
  5. ?>

a) In for loop
b) After for loop
c) In for loopAfter for loop
d) Infinite loop

View Answer

Answer: b [Reason:] The loop does not run as i initialized in check statement will be zero.

10. What will be the output of the following PHP code ?

  1. <?php
  2. for ($i == 2; ++$i == $i; ++$i)
  3.     print "In for loop ";
  4. print "After loopn";
  5. ?>

a) In for loopIn for loopIn for loopIn for loop……infinitely
b) After for loopAfter for loopAfter for loop……..infinitely
c) In for loopAfter for loopIn for loopAfter for loopIn for loopAfter for loop…..infinitely
d) After for loop

View Answer

Answer: a [Reason:] The loop never exits as the condition ++X == X is always satisfied,evaluated from right to left.

PHP MCQ Set 5

1. What will be the output of the following PHP code ?

  1. <?php
  2. for ($x = 1; $x < 10; $x++)
  3.     for ($y = 1; $y < 5; $y++)
  4.         print "Hello";
  5. ?>

a) Hello….36 times
b) Hello….45 times
c) Hello….50 times
d) Hello….40 times

View Answer

Answer: a [Reason:] 9*4 times is printed.

2. What will be the output of the following PHP code ?

  1. <?php
  2. for ($count = 1; $count != 20;$count++)
  3. {
  4.     print $count;
  5.     $count++;
  6. }
  7. ?>

a) Infinite
b) 123…….20
c) 1357…19
d) 13579…21

View Answer

Answer: a [Reason:] Condition always fails as count takes only odd numbers.

3. What will be the output of the following PHP code ?

  1. <?php
  2. for ($count = 1; $count < 20; $count++);
  3.     print $count;
  4. ?>

a) 20
b) 19
c) 12345678910….19
d) 12345678910….1920

View Answer

Answer: a [Reason:] The for loop has no body,it just runs till condition is satisfied.

4. What will be the output of the following PHP code ?

  1. <?php
  2. for ($count = 0; $count < 3;$count++);
  3. {
  4.     print "hi";continue;print "hello";
  5. }
  6. ?>

a) hihihi
b) hihellohihellohihello
c) hellohellohello
d) hi

View Answer

Answer: a [Reason:] When continue is encountered it skips to the next iteration

5. What will be the output of the following PHP code ?

  1. <?php
  2. for ($count = 0; $count<3;$count++);
  3. {
  4.     print "hi";break;print "hello";
  5. }
  6. ?>

a) hihihi
b) hihellohihellohihello
c) hellohellohello
d) hi

View Answer

Answer: d [Reason:] When break is encountered it leaves the loop.

6. What will be the output of the following PHP code ?

  1. <?php
  2. for(++$i; ++$i; ++$i)
  3. {
  4.     print $i;
  5.     if ($i == 4) 
  6.         break;
  7. }
  8. ?>

a) 24
b) 134
c) 1234
d) 1

View Answer

Answer: a [Reason:] The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on.

7. What will be the output of the following PHP code ?

  1. <?php
  2. for ($i = 0;$i = -1;$i = 1)
  3. {
  4.     print $i;
  5.     if ($i != 1) 
  6. 	break;
  7. }
  8. ?>

a) 0
b) infinite loop
c) -1
d) 1

View Answer

Answer: c [Reason:] The order of execution is initialization, check, increment/decrement, check, increment/decrement, check, increment/decrement….so on .

8. What will be the output of the following PHP code ?

  1. <?php
  2. for(;;)
  3. {
  4.    print "10";
  5. }
  6. ?>

a) 10
b) infinite loop
c) no output
d) error

View Answer

Answer: b [Reason:] There is no check condition to stop the execution of the loop.

9. What will be the output of the following PHP code ?

  1. <?php
  2. for ($i = 0; $i < 3; $i++)
  3. {
  4.     for($j = $i; $j > 0; $j--)
  5.         print " ";
  6.     for($k = $j; $k < 3; $k++)
  7.         print "*";
  8. 	print "n";  
  9. }
  10. ?>

a)
*
**
***
b) ***
**
*
c) *
**
***
d) error

View Answer

Answer: a [Reason:] Follow the trace of i, j prints 3 – i no of spaces for each i, k prints i stars for each loop.

10. What will be the output of the following PHP code ?

  1. <?php
  2. for ($i = 0; -5 ; $i++)
  3. {
  4.     print"i";
  5.     if ($i == 3)
  6.         break;
  7. }
  8. ?>

a) 0 1 2 3 4
b) 0 1 2 3
c) 0 1 2 3 4 5
d) error

View Answer

Answer: b [Reason:] The break statement after breaks the loop after i=3,does not print anymore.

PHP MCQ Set 6

1. What will be the output of the following PHP code?

  1. <?php
  2. $cars = array("Volvo", "BMW", "Toyota");
  3. echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
  4. ?>

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)

View Answer

Answer: b [Reason:] The array() function is used to create an array.

2. What will be the output of the following PHP code?

  1. <?php
  2. $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
  3. print_r(array_change_key_case($age, CASE_UPPER));
  4. ?>

a) Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
b) Array ( [peter] => 35 [ben] => 37 [joe] => 43 )
c) Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
d) Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )

View Answer

Answer: c [Reason:] The array_change_key_case() function changes all keys in an array to lowercase or uppercase.

3. What will be the output of the following PHP code?

  1. <?php
  2. $cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes", "Opel");
  3. print_r(array_chunk($cars, 2));
  4. ?>

a) Array ( [0] => Array ( [1] => Volvo [2] => BMW ) [1] => Array ( [1] => Toyota [2] => Honda ) [2] => Array ( [1] => Mercedes [2] => Opel ) )
b) Array ( [1] => Array ( [1] => Volvo [2] => BMW ) [2] => Array ( [1] => Toyota [2] => Honda ) [3] => Array ( [1] => Mercedes [2] => Opel ) )
c) Array ( [0] => Array ( [0] => Volvo [1] => Volvo ) [1] => Array ( [0] => BMW [1] => BMW ) [2] => Array ( [0] => Toyota [1] => Toyota ) )
d) Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )

View Answer

Answer: d [Reason:] The array_chunk() function splits an array into chunks of new arrays.

4. What will be the output of the following PHP code?

  1. <?php
  2. $fname = array("Peter", "Ben", "Joe");
  3. $age = array("35", "37", "43");
  4. $c = array_combine($fname, $age);
  5. print_r($c);
  6. ?>

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

View Answer

Answer: b [Reason:] The array_combine() function creates an array by using the elements from one “keys” array and one “values” array.

5. What will be the output of the following PHP code?

  1. <?php
  2. $a = array("A", "Cat", "Dog", "A", "Dog");
  3. print_r(array_count_values($a));
  4. ?>

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)

View Answer

Answer: a [Reason:] The array_count_values() function counts all the values of an array.

6. What will be the output of the following PHP code?

  1. <?php
  2. $a1 = array("a"=>"red", "b"=>"green", "c"=>"blue", "d"=>"yellow");
  3. $a2 = array("e"=>"red", "f"=>"green", "g"=>"blue");
  4. $result = array_diff($a1, $a2);
  5. print_r($result);
  6. ?>

a) Array ( [d] => yellow )
b) Array ( [c] => blue )
c) Array ( [a] => red )
d) Array ( [e] => yellow )

View Answer

Answer: a [Reason:] The array_diff() function compares the values of two (or more) arrays, and returns the differences.

7. What will be the output of the following PHP code?

  1. <?php
  2. $a1 = array_fill(3, 4, "blue");
  3. $b1 = array_fill(0, 1, "red");
  4. print_r($a1);
  5. echo "<br>";
  6. print_r($b1);
  7. ?>

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 )

View Answer

Answer: d [Reason:] The array_fill() function fills an array with values.

8. What will be the output of the following PHP code?

  1. <?php
  2. $a1 = array("red", "green");
  3. $a2 = array("blue", "yellow");
  4. print_r(array_merge($a1, $a2));
  5. ?>

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 )

View Answer

Answer: c [Reason:] The array_merge() function merges one or more arrays into one array.

9. What will be the output of the following PHP code?

  1. <?php
  2. $a = array("a"=>"red", "b"=>"green", "c"=>"blue");
  3. echo array_shift($a);
  4. print_r ($a);
  5. ?>

a) green
b) red
c) blue
d) none of the mentioned

View Answer

Answer: b [Reason:] The array_shift() function removes the first element from an array, and returns the value of the removed element.

10. What will be the output of the following PHP code?

  1. <?php
  2. $a = array("red", "green", "blue");
  3. array_pop($a);
  4. print_r($a);
  5. ?>

a) Array ( [0] => red [1] => green )
b) Array ( [0] => green [1] => blue )
c) Array ( [0] => red [1] => blue )
d) Array ( [0] => blue [1] => blue )

View Answer

Answer: a [Reason:] The array_pop() function deletes the last element of an array.

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com