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

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

Which PHP function is used to merge two or more arrays into a single array?

A). merge()

B). combine()

C). concat()

D). array_merge()

What will be the output of the following PHP code?
<?php
$colors = array('Red' => 1, 'Green' => 2, 'Blue' => 3);
asort($colors);
foreach ($colors as $color => $value) {
echo '$color: $value ';
}
?

A). Red: 1 Green: 2 Blue: 3

B). 1: Red 2: Green 3: Blue

C). 1: Blue 2: Green 3: Red

D). Red: 3 Green: 2 Blue: 1

What will be the output of the following PHP code?
<?php
$numbers = array(10, 20, 30, 40, 50);
array_pop($numbers);
foreach ($numbers as $number) {
echo $number . ' ';
}
?

A). 20 30 40 50

B). 10 20 30 40

C). 10 20 30 40

D). 10 20 30 40 50

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 will be the output of the following PHP code?
<?php
$numbers = array(10, 20, 30, 40, 50);
echo count($numbers);
?

A). 10

B). 20

C). 5

D). 50

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

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

What will be the output of the following PHP code?
<?php
$colors = array('Red', 'Green', 'Blue');
array_push($colors, 'Yellow', 'Orange');
foreach ($colors as $color) {
echo $color . ' ';
}
?

A). Red Green Blue Yellow Orange

B). Yellow Orange Red Green Blue

C). Green Blue Red Yellow Orange

D). Yellow Orange