"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 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
$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 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
$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 is the correct syntax for creating a multidimensional array in PHP?

A). $array = array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9));

B). $array = array([1, 2, 3], [4, 5, 6], [7, 8, 9]);

C). $array = array{1, 2, 3}, {4, 5, 6}, {7, 8, 9};

D). $array = array{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

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
$numbers = array(10, 20, 30, 40, 50);
echo count($numbers);
?

A). 10

B). 20

C). 5

D). 50

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

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

A). remove()

B). pop()

C). delete()

D). unset()