Q
What is the correct syntax for creating a multidimensional array in PHP?

Answer & Solution

Answer: Option A
Solution:
The correct syntax for creating a multidimensional array in PHP is $array = array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9));. Each nested array() represents a separate dimension of the array.
Related Questions on Average

Which PHP function is used to determine the number of elements in an array?

A). size()

B). count()

C). length()

D). elements()

What will be the output of the following PHP code?
<?php
$info = array('name' => 'Alice', 'age' => 25);
echo count($info);
?

A). 1

B). 2

C). 25

D). Alice

What will be the output of the following PHP code?
<?php
$info = array('name' => 'John', 'age' => 30, 'city' => 'New York');
echo array_key_exists('age', $info) ? 'Yes' : 'No';
?

A). Yes

B). No

C). John

D). 30

What will be the output of the following PHP code?
<?php
$person = array('name' => 'John', 'age' => 30, 'city' => 'New York');
echo $person['age'];
?

A). name: John

B). age: 30

C). city: New York

D). John

What is the purpose of the array_push() function in PHP?

A). To remove elements from an array

B). To add elements to the beginning of an array

C). To add elements to the end of an array

D). To reverse the order of elements in an array

What is the purpose of the array_key_exists() function in PHP?

A). To check if a specified key exists in an array

B). To check if a specified value exists in an array

C). To retrieve all keys from an array

D). To retrieve all values from an array

What will be the output of the following PHP code?
<?php
$arr1 = array('a', 'b', 'c');
$arr2 = array(1, 2, 3);
$result = array_merge($arr1, $arr2);
foreach ($result as $item) {
echo $item . ' ';
}
?

A). a b c 1 2 3

B). 1 2 3 a b c

C). a b c

D). 1 2 3

Which PHP function is used to sort an array in ascending order, maintaining the key-value pairs?

A). sort()

B). ksort()

C). asort()

D). rsort()

What is the correct way to access the first element of an indexed array in PHP?

A). $array[0]

B). $array[1]

C). $array['first']

D). $array['0']

Which of the following statements is true about associative arrays in PHP?

A). They only allow numeric indices

B). They store elements in a sequential order

C). They use key-value pairs to access elements

D). They cannot be accessed using loop constructs