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

Answer & Solution

Answer: Option B
Solution:
The output of the code will be 2 because the count() function in PHP returns the number of elements in an array. In this case, the $info array contains two elements ('name' and 'age'), so count($info) will return 2.
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()

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

What is the output of the following PHP code?
<?php
$colors = array('Red', 'Green', 'Blue');
echo $colors[1];
?

A). Red

B). Green

C). Blue

D). 1

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

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

A). splice()

B). slice()

C). extract()

D). split()

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