$arr2 = array(1, 2, 3);
$result = array_merge($arr1, $arr2);
foreach ($result as $item) {
echo $item . " ";
}
? | PHP | MYTAT"> $arr2 = array(1, 2, 3);
$result = array_merge($arr1, $arr2);
foreach ($result as $item) {
echo $item . " ";
}
? | PHP | MYTAT">
Q
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 . ' ';
}
?

Answer & Solution

Answer: Option A
Solution:
The output of the code will be a b c 1 2 3 because the array_merge() function merges the elements of $arr1 and $arr2 into a single array $result. The foreach loop then iterates over the merged array, printing each item, resulting in the output a b c 1 2 3.
Related Questions on Average

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);
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 remove the last element from an array?

A). remove()

B). pop()

C). delete()

D). unset()

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

A). String

B). Integer

C). Key-value pairs

D). Floating-point number

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