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

Answer & Solution

Answer: Option B
Solution:
The output of the code will be 30 because associative arrays in PHP use key-value pairs to access elements, where each element is associated with a specific key. In this case, $person['age'] refers to the value associated with the key 'age', which is 30.
Related Questions on Average

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

A). merge()

B). combine()

C). concat()

D). array_merge()

Which PHP construct is commonly used to iterate over elements of an array?

A). foreach loop

B). while loop

C). do-while loop

D). for loop

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

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

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 type of index do indexed arrays in PHP use?

A). String

B). Integer

C). Key-value pairs

D). Floating-point number

Which PHP function is used to extract a slice of an array?

A). splice()

B). slice()

C). extract()

D). split()

What will be the output of the following PHP code?
<?php
$matrix = array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9)
);
echo $matrix[1][2];
?

A). 1

B). 2

C). 4

D). 6

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

A). size()

B). count()

C). length()

D). elements()

Which PHP function is used to remove the last element from an array?

A). remove()

B). pop()

C). delete()

D). unset()