PHP Arrays Quiz

Last Updated :
Discuss
Comments

Question 1

What type of array uses numeric indexes starting from 0 in PHP?

  • A

    Associative Array

  • B

    Indexed Array

  • C

    Multidimensional Array

  • D

    Static Array

Question 2

Which type of PHP array uses named keys instead of numeric indexes?

  • A

    Indexed Array

  • B

    Static Array

  • C

    Associative Array

  • D

    Multidimensional Array

Question 3

What is a multidimensional array in PHP?

  • A

    An array containing only numeric values

  • B

    An array containing other arrays as elements

  • C

    An array that only stores strings

  • D

    An array with a fixed size

Question 4

Which PHP function adds elements to the end of an indexed array?

  • A

    array_unshift()

  • B

    array_push()

  • C

    array_pop()

  • D

    unset()

Question 5

How can you remove the last element from an indexed array?

  • A

    array_shift()

  • B

    array_pop()

  • C

    unset()

  • D

    array_unshift()

Question 6

How do you sort the array $numbers = [3, 1, 4, 1, 5]; in ascending order?

  • A

    sort($numbers);

  • B

    rsort($numbers);

  • C

    asort($numbers);

  • D

    ksort($numbers);

Question 7

How do you merge two arrays $array1 = [1, 2, 3]; and $array2 = [4, 5, 6];?

  • A

    $merged = $array1 + $array2;

  • B

    $merged = array_merge($array1, $array2);

  • C

    $merged = array_combine($array1, $array2);

  • D

    $merged = array_intersect($array1, $array2);

Question 8

How to count the number of elements in the array $numbers?

  • A

    length($numbers);

  • B

    array_size($numbers);

  • C

    count($numbers);

  • D

    total($numbers);

Question 9

What is the difference between array_shift() and array_pop()?

  • A

    array_shift() adds an element to start, array_pop() removes from the end

  • B

    array_shift() removes first element, array_pop() removes last element

  • C

    array_shift() removes the the last element, array_pop() removes the first element

  • D

    Both remove the last element

Question 10

How do you access the "name" element in the associative array $person = ["name" => "GFG", "age" => 30];?

  • A

    echo $person[1];

  • B

    echo $person["name"];

  • C

    echo $person["GFG"];

  • D

    echo $person["age"];

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion