"John", "age" => 30, "city" => "New York");
echo array_key_exists("age", $info) ? "Yes" : "No";
? | PHP | MYTAT"> "John", "age" => 30, "city" => "New York");
echo array_key_exists("age", $info) ? "Yes" : "No";
? | PHP | MYTAT">
Q
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';
?

Answer & Solution

Answer: Option A
Solution:
The output of the code will be Yes because the array_key_exists() function checks if the key 'age' exists in the $info array, which it does. Therefore, the expression will evaluate to true, and 'Yes' will be echoed.
Related Questions on Average

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

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 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 function is used to remove the last element from an array?

A). remove()

B). pop()

C). delete()

D). unset()

What will be the output of the following PHP code?
<?php
$arr = array(10, 20, 30, 40, 50);
$slice = array_slice($arr, 2);
foreach ($slice as $item) {
echo $item . ' ';
}
?

A). 10 20 30 40 50

B). 10 20

C). 30 40 50

D). 30 40 50

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

A). splice()

B). slice()

C). extract()

D). split()

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