<?php
$colors = array('Red', 'Green', 'Blue');
array_push($colors, 'Yellow', 'Orange');
foreach ($colors as $color) {
echo $color . ' ';
}
?
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 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
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 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
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()
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
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
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
$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