bidezones.com /PHP/PHP Mcq Arrays Sample Test,Sample questions

Question:
 Key/value pair can be initialized using = operator?

1. True

2.False

3.Depend on program

4.Keys does not exist in array

Posted Date:-2022-02-16 11:37:04


Question:
 PHP’s numerically indexed array begin with position ___________

1.1

2.2

3.0

4. -1

Posted Date:-2022-02-16 10:31:18


Question:
 Predict the output of the following code.

<?php

$a=array(1,2,3,5,6);
next($a);
next($a);
next($a);
echo current($a);

?>

1.2

2.3

3.4

4.5

Posted Date:-2022-02-16 11:51:05


Question:
 Predict the output of the following PHP code.

<?php

$fruits = array ("apple", "orange", "banana", "guava", "pine-apple", "papaya", "melon");
next($fruits);
next($fruits);
prev($fruits);

?>

1.guava

2.banana

3.orange

4.pine-apple

Posted Date:-2022-02-16 11:53:26


Question:
 What is the use of array_unshift() function?

1.Function is used to print the array in readable format.

2. Adds elements to the beginning of the array and returns the size of array

3.Function can be used to verify if a variable is an array. Returns TRUE or FALSE

4.Adds elements to the end of the array and returns the size of array.

Posted Date:-2022-02-16 11:48:07


Question:
 What will be the output of the following PHP code?

    <?php
    $face = array ("A", "J", "Q", "K");
    $number = array ("2","3","4", "5", "6", "7", "8", "9", "10");
    $cards = array_merge ($face, $number);
    print_r ($cards);
    ?>

1.Array ( [0] => A [1] => J [2] => Q [3] => K [4] => 2 [5] => 3 [6] => 4 [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )

2.Array ( [0] => A [1] => 2 [2] => J [3] => 3 [4] => Q [5] => 4 [6] => K [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )

3.Error

4.Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9] => A [10] => J [11] => Q [12] => K )

Posted Date:-2022-02-16 12:30:32


Question:
 What will be the output of the following PHP code?

    <?php
    $fruits = array ("apple", "orange", array ("pear", "mango"),
    "banana");
    echo (count($fruits, 1));
    ?>

1.3

2.4

3.5

4.6

Posted Date:-2022-02-16 10:37:55


Question:
 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) );
    ?>

1. True

2.1

3.False

4.2

Posted Date:-2022-02-16 10:35:31


Question:
 What will be the output of the following PHP code?

<?php
$a = array("A", "Cat", "Dog", "A", "Dog");
print_r(array_count_values($a));
?>

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

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

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

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

Posted Date:-2022-02-16 12:15:07


Question:
 What will be the output of the following PHP code?

<?php
$a = array("red", "green", "blue");
array_pop($a);
print_r($a);
?>

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

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

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

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

Posted Date:-2022-02-16 12:21:48


Question:
 What will be the output of the following PHP code?

<?php
$a1 = array("red", "green");
$a2 = array("blue", "yellow");
$a3 = array_merge($a1, $a2);
$a4 = array("a", "b", "c", "d");
$a = array_combine($a4, $a3);
print_r($a);
?>

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

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

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

4.Array ( [a] => red [b] => green [c] => blue [d] => yellow )

Posted Date:-2022-02-16 10:46:27


Question:
 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));
?>

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

2.Array ( [peter] => 35 [ben] => 37 [joe] => 43 )

3.Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )

4.Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )

Posted Date:-2022-02-16 12:02:53


Question:
 What will be the output of the following PHP code?

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

1. I like Volvo, Toyota and BMW

2. I like Volvo, BMW and Toyota

3.I like BMW, Volvo and Toyota

4.I like Toyota, BMW and Volvo

Posted Date:-2022-02-16 10:40:43


Question:
 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));
?>

1.Array ( [0] => Array ( [1] => Volvo [2] => BMW ) [1] => Array ( [1] => Toyota [2] => Honda ) [2] => Array ( [1] => Mercedes [2] => Opel ) )

2.Array ( [1] => Array ( [1] => Volvo [2] => BMW ) [2] => Array ( [1] => Toyota [2] => Honda ) [3] => Array ( [1] => Mercedes [2] => Opel ) )

3.Array ( [0] => Array ( [0] => Volvo [1] => Volvo ) [1] => Array ( [0] => BMW [1] => BMW ) [2] => Array ( [0] => Toyota [1] => Toyota ) )

4.Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )

Posted Date:-2022-02-16 12:04:19


Question:
 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);
?>

1.Array ( Peter Ben Joe )

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

3. Array ( 35 37 43 )

4.Array ( “[Peter] => 35” “[Ben] => 37” “[Joe] => 43” )

Posted Date:-2022-02-16 12:13:33


Question:
 What will be the output of the following PHP code?

<?php
$names = array("Sam", "Bob", "Jack");
echo $names[0] . "is the brother of " . $names[1] . " and " . $names[1] . ".";
?>

1.Sam is the brother of Bob and Jack

2.Samis the brother of Bob and Bob

3.Sam is the brother of Jack and Bob

4.Error

Posted Date:-2022-02-16 10:51:13


Question:
 Which in-built function will add a value to the end of an array?

1.array_unshift()

2.into_array()

3.inend_array()

4.array_push()

Posted Date:-2022-02-16 11:30:52


Question:
 Which in-built function will add a value to the end of an array?

1. array_unshift()

2. into_array()

3.inend_array()

4. array_push()

Posted Date:-2022-02-16 10:34:35


Question:
 Which of the following are correct ways of creating an array?

i) state[0] = "karnataka";
ii) $state[] = array("karnataka");
iii) $state[0] = "karnataka";
iv)  $state = array("karnataka");

1. iii) and iv)

2. ii) and iii)

3.Only i)

4.ii), iii) and iv)

Posted Date:-2022-02-16 10:32:41


Question:
A ________ is an array with more than two dimensions.

1. A. single dimensional array

2.multi dimensional array

3.Both A and B

4.None of the above

Posted Date:-2022-02-16 11:11:39


Question:
As compared to associative arrays vector arrays are much

1.Faster

2.Slower

3.Stable

4.None of the above

Posted Date:-2022-02-16 11:34:23


Question:
By default, the index of array in php starts from ______?

1. 0

2.1

3.-1

4.2

Posted Date:-2022-02-16 11:08:40


Question:
What is the output of the following php code?

<?php
 $alphabet  = array("A" => array
 ( "php" => "php 7.0", "date" => "3 December 2019"),
 "B" => array( "python" => "python 3.8.2",
 "date" => "24 December 2019") );
 echo $alphabet ["A"]["date"];
 ?>

1. php 7.0

2. 3 December 2019

3. python 3.8.2

4.24 December 2019

Posted Date:-2022-02-16 11:35:56


Question:
What is the output of the following php code?

<?php
 $alphabet = array ("A", "B", "C");
 echo (next($alphabet));
 ?>

1.A

2.B

3.C

4.Error

Posted Date:-2022-02-16 11:34:51


Question:
What is the use of array_flip() function?

1.Rearranges the array elements in the reverse order

2.Is used to convert the keys to values and values to keys.

3.Can be used to fetch the keys present in the array

4.Returns number of elements in the array

Posted Date:-2022-02-16 11:49:43


Question:
What is the use of array_values() function?

1.Returns all the values of the respective keys present in the passed array

2.Returns number of elements in the array

3.Can be used to fetch the keys present in the array

4. Returns the values and the frequency of each value in form of an array.

Posted Date:-2022-02-16 11:50:32


Question:
What is the use of is_array() function?

1.Function is used to print the array in readable format.

2.Adds elements to the beginning of the array and returns the size of array.

3.Function can be used to verify if a variable is an array. Returns TRUE or FALSE

4.Adds elements to the end of the array and returns the size of array.

Posted Date:-2022-02-16 11:43:43


Question:
What will be the output of the following PHP code?

    <?php
    $arr = array ("picture1.JPG", "picture2.jpg",
    "Picture10.jpg", "picture20.jpg");
    sort($arr);
    print_r($arr);
    ?>

1.Array ( [0] => picture1.JPG [1] => Picture10.jpg [2] => picture2.jpg [3] => picture20.jpg )

2. Array ( [0] => picture1.JPG [1] => picture2.jpg [2] => Picture10.jpg [3] => picture20.jpg )

3.Array ( [0] => Picture10.jpg [1] => picture1.JPG [2] => picture2.jpg [3] => picture20.jpg )

4.Array ( [0] => Picture10.jpg [1] => picture1.JPG [2] => picture20.jpg [3] => picture2.jpg )

Posted Date:-2022-02-16 12:27:28


Question:
What will be the output of the following PHP code?

    <?php
    $array1 = array ("KA", "LA", "CA", "MA", "TA");
    $array2 = array ("KA", "IA", "CA", "GA", "TA");
    $inter = array_intersect ($array1, $array2);
    print_r ($inter);
    ?>

1.Array ( [0] => KA [1] => LA [2] => CA [3] => MA [4] => TA [5] => IA [6] => GA )

2.Array ( [0] => KA [2] => CA [4] => TA )

3.Array ( [1] => IA [3] => GA )

4.Array ( [1] => LA [3] => MA )

Posted Date:-2022-02-16 12:41:02


Question:
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);
    ?>

1.Array ( [0] => peach )

2.Array ( [0] => apple [1] => mango [2] => peach )

3.Array ( [0] => apple [1] => mango )

4.Array ( [0] => peach [1] => pear [2] => orange )

Posted Date:-2022-02-16 12:33:01


Question:
What will be the output of the following PHP code?

    <?php
    $fruits = array ("apple", "mango", "peach", "pear",
    "orange");
    $subset = array_splice ($fruits, 2);
    print_r ($fruits);
    ?>

1.Error

2.Array ( [0] => apple [1] => mango [2] => peach )

3. Array ( [0] => apple [1] => mango ) d)

4.Array ( [0] => pear [1] => orange

Posted Date:-2022-02-16 12:37:26


Question:
What will be the output of the following PHP code?

    <?php
    $fruits = array ("apple", "orange", "banana");
    echo (next($fruits));	
    echo (next($fruits));
    ?>

1.orangebanana

2.appleorange

3.orangeorange

4.appleapple

Posted Date:-2022-02-16 10:36:25


Question:
What will be the output of the following PHP code?

    <?php
    $fruits = array ("mango", "apple", "pear", "peach");
    $fruits = array_flip($fruits);
    echo ($fruits[0]);
    ?>

1.mango

2.error

3.peach

4.0

Posted Date:-2022-02-16 12:23:18


Question:
What will be the output of the following PHP code?

    <?php
    $number = array ("4", "hello", 2);
    echo (array_sum ($number));
    ?>

1.4hello2

2.4

3.2

4.6

Posted Date:-2022-02-16 12:39:45


Question:
What will be the output of the following PHP code?

<?php
    $arr = array ("lets", "find", "course", ".Com");
    echo (array_search (".com", $arr) );
?>

1. 0

2.Garbage value

3.3

4.No Output

Posted Date:-2022-02-16 11:33:19


Question:
What will be the output of the following PHP code?

<?php
$a = array("a" => "india", "b" => "brazil", "c" => "china");
echo array_shift($a);
echo "<br>";
array_pop($a);
print_r($a);
?>

1.india Array ( [b] => Brazil )

2.india Array ( [a] => brazil )

3.china Array ( [a] => india )

4.china Array ( [a] => brazil )

Posted Date:-2022-02-16 10:47:37


Question:
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);
?>

1.green

2.red

3.redArray( [c] => green [c] => blue )

4.redArray( [b] => green [c] => blue )

Posted Date:-2022-02-16 12:20:07


Question:
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", "h" => "orange");
$a3 = array("i" => "orange");
$a4 = array_merge($a2, $a3);
$result = array_diff($a1, $a4);
print_r($result);
?>

1.Array ( [d] => yellow )

2. Array ( [i] => orange )

3.Array ( [h] => orange )

4. Array ( [d] => yellow [h] => orange )

Posted Date:-2022-02-16 10:45:29


Question:
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));
?>

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

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

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

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

Posted Date:-2022-02-16 12:18:26


Question:
What will be the output of the following PHP code?

<?php
$a1 = array_fill(1, 4, "hello");
$b1 = array_fill(5, 1, "php");
$a2 = array_merge($a1, $a2);
print_r($a2);
echo "<br>";
print_r($b1);
?>

1.Array ( [1] => hello [4] => hello [5] => php ) Array ( [5] => php )

2.Array ( [1] => hello [2] => hello [3] => hello [4] => hello ) Array ( [5] => php )

3.Array ( [1] => hello [2] => hello [3] => hello [4] => hello [5] => php ) Array ( [5] => php )

4.Array ( [1] => hello [2] => hello [3] => hello [4] => hello ) Array ( [1] => php )

Posted Date:-2022-02-16 10:50:35


Question:
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 "<br>";
print_r($b1);
?>

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

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

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

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

Posted Date:-2022-02-16 12:17:03


Question:
What will be the output of the following PHP code?

<?php
$a=array("A","Cat","Dog","A","Dog");
$b=array("A","A","Cat","A","Tiger");
$c=array_combine($a,$b);
print_r(array_count_values($c));
?>

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

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

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

4.Array ( [A] => 2 [Tiger] => 1 )

Posted Date:-2022-02-16 10:42:57


Question:
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] . ".";
?>

1.I like Volvo BMW and Toyota.

2.I like Volvo, BMW and Toyota)

3.I like Volvo, BMW and Toyota

4. I like. Volvo.,. BMW. and. Toyota)

Posted Date:-2022-02-16 12:01:35


Question:
What will be the output of the following PHP code?

<?php
$fname = array("Peter", "Ben", "Joe");
$age = array("35", "37", "43");
$c = array_combine($age, $fname);
print_r($c);
?>

1.Array (Peter Ben Joe)

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

3.Array (35 37 43)

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

Posted Date:-2022-02-16 10:41:53


Question:
What will be the output of the following PHP code?

<?php
$names = array("Sam", "Bob", "Jack");
echo $names[0]."is the brother of ".$names[1]." and ".$names[1].".".$brother;
?>

1.Sam is the brother of Bob and Bob) $brother

2.Sam is the brother of Bob and Bob)

3.$brother

4.Error

Posted Date:-2022-02-16 10:52:24


Question:
Which function returns an array consisting of associative key/value pairs?

1.count()

2.array_count()

3.array_count_values()

4.count_values()

Posted Date:-2022-02-16 11:31:32


Question:
Which function returns an array consisting of associative key/value pairs?

1.count()

2. array_count()

3.array_count_values()

4.count_values()

Posted Date:-2022-02-16 10:39:00


Question:
Which function should we use to sort the array in natural order?

1.dsort()

2.casesort()

3.natcasesort()

4.naturalsort()

Posted Date:-2022-02-16 12:28:33


Question:
Which of the following are correct ways of creating an array?
i) arr[0] = "letsfindcourse";
ii) $arr[] = array("letsfindcourse");
iii) $arr[0] = "letsfindcourse";
iv) $arr = array("letsfindcourse");

1.ii), iii) and iv)

2.ii) and iii)

3.Only i) D

4.iii) and iv)

Posted Date:-2022-02-16 11:12:53


Question:
Which of the following function is used to get the value of the previous element in an array?

1.last()

2.before()

3.prev()

4.previous()

Posted Date:-2022-02-16 11:54:27


Question:
Which of the following function is used to get the value of the previous element in an array?

1. last()

2.before()

3.prev()

4.previous()

Posted Date:-2022-02-16 10:37:21


Question:
Which of the following function is Used to set the array pointer to the value of last key?

1.last()

2.end()

3.next()

4.final()

Posted Date:-2022-02-16 11:55:12


Question:
Which of the following PHP function will return true if a variable is an array or false if it is not an array?

1.this_array()

2. is_array()

3.do_array()

4. in_array()

Posted Date:-2022-02-16 10:33:38


Question:
Which of the functions is used to sort an array in descending order?

1.sort()

2.asort()

3.rsort()

4.dsort()

Posted Date:-2022-02-16 12:24:37


More MCQS[bidezones.com ]

  1. PHP Mcq Set 1
  2. PHP Mcq Set 2
  3. PHP Mcq Set 3
  4. PHP Mcq Set 4
  5. Current affairs mcq php
  6. Current affairs mcq php set 2
  7. Current affairs mcq php set 3
  8. PHP MCQ
  9. PHP MCQ Basics
  10. PHP Mcq Functions
  11. PHP Mcq Arrays
  12. PHP Mcq Basics of Object-Oriented PHP
  13. PHP Mcq Error Handling
  14. PHP Basics Mcq Questions