PHP Array MCQs
This section focuses on "Array" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. How many types of array are available in php?
Explanation: There are basically three types of arrays in PHP: Indexed or Numeric Arrays, Associative Arrays, Multidimensional Arrays
2. By default, the index of array in php starts from ______?
Explanation: By default, the index starts from zero.
3. A ________ is an array with more than two dimensions.
Explanation: A multidimensional array is an array with more than two dimensions. In a matrix, the two dimensions are represented by rows and columns
4. Which of the following are correct ways of creating an array?
i) arr = "letsfindcourse";
ii) $arr = array("letsfindcourse");
iii) $arr = "letsfindcourse";
iv) $arr = array("letsfindcourse");
Explanation: A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when you use the array(), constructor.
5. Which in-built function will add a value to the end of an array?
Explanation: array_push adds value to the end of an array, returning the total count of elements in the array after the new value has been added.
6. Which function returns an array consisting of associative key/value pairs?
Explanation: The function array_count_values() will count all the values of an array.
7. What will be the output of the following PHP code?
$arr = array ("lets", "find", "course", ".Com");
echo (array_search (".com", $arr) );
Explanation: Due to case-sensitive .com is not in an array so there will be no output.
8. As compared to associative arrays vector arrays are much
Explanation: As compared to associative arrays vector arrays are much Faster.
9. What is the output of the following php code?
$alphabet = array ("A", "B", "C");
Explanation: The next function is an in-built function used to print the next value of the current index. As the current index value is 0 so next will print value B.
10. What is the output of the following php code?
$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"];
Explanation: The output of the following PHP code is 3 December 2015.
Also check :