ExamVeda
Login
Home
21
What will be the output of the following PHP code ?
<?php
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
$a2 = array("e" => "red","f" => "green", "g" => "blue");
$result = array_intersect($a1, $a2);
print_r($result);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The array_intersect() function compares the values of two (or more) arrays, and returns the matches.
22
What will be the output of the following PHP code ?
<?php
$a = array(12, 5, 2);
echo(array_product($a));
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The array_product() function calculates and returns the product of an array.
23
What will be the output of the following PHP code ?
<?php
$a = array("a" => "Jaguar", "b" => "Land Rover", "c" => "Audi", "d" => "Maseratti");
echo array_search("Audi", $a);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The array_search() function searches for the element and returns the key of that element.
24
What will be the output of the following PHP code ?
<?php
$city_west = array("NYC", "London");
$city_east = array("Mumbai", "Beijing");
print_r(array_replace($city_west, $city_east));
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The array_replace() function replaces the values of the first array with the values from following arrays
25
What will be the output of the following PHP code ?
<?php
$people = array("Peter", "Susan", "Edmund", "Lucy");
echo pos($people);
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The pos() function returns the value of the current element in an array, and since no operation has been done, the current element is the first element.
26
What will be the output of the following PHP code ?
<?php
$number = range(0, 5);
print_r ($number);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The range() function creates an array containing a range of elements.
27
What will be the output of the following PHP code ?
<?php
$array = array("red", "green");
array_push($array, "blue", "yellow");
print_r($array);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The array_push() function inserts one or more elements to the end of an array.
28
What will be the output of the following PHP code?
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
print_r(array_change_key_case($age, CASE_UPPER));
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The array_change_key_case() function changes all keys in an array to lowercase or uppercase.
29
What will be the output of the following PHP code?
<?php
$cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes", "Opel");
print_r(array_chunk($cars, 2));
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The array_chunk() function splits an array into chunks of new arrays.
30
What will be the output of the following PHP code?
<?php
$fname = array("Peter", "Ben", "Joe");
$age = array("35", "37", "43");
$c = array_combine($fname, $age);
print_r($c);
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The array_combine() function creates an array by using the elements from one “keys” array and one “values” array.