ExamVeda
Login
Home
31
What will be the output of the following PHP code?
<?php
$a = array("A", "Cat", "Dog", "A", "Dog");
print_r(array_count_values($a));
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The array_count_values() function counts all the values of an array.
32
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_diff($a1, $a2);
print_r($result);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The array_diff() function compares the values of two (or more) arrays, and returns the differences.
33
What will be the output of the following PHP code?
<?php
$a1 = array("red", "green");
$a2 = array("blue", "yellow");
print_r(array_merge($a1, $a2));
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The array_merge() function merges one or more arrays into one array.
34
What will be the output of the following PHP code?
<?php
$a = array("a"=>"red", "b"=>"green", "c"=>"blue");
echo array_shift($a);
print_r ($a);
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The array_shift() function removes the first element from an array, and returns the value of the removed element.
35
What will be the output of the following PHP code?
<?php
$a = array("red", "green", "blue");
array_pop($a);
print_r($a);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The array_pop() function deletes the last element of an array.
36
What will be the output of the following PHP code?
<?php
$fruits = array ("mango", "apple", "pear", "peach");
$fruits = array_flip($fruits);
echo ($fruits[0]);
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
As we are flipping the values, $fruits[“mango”] = 0, $fruits[“apple”] = 1 and so on.
37
What will be the output of the following PHP code?
<?php
$fruits = array ("mango", "apple", "peach", "pear");
$fruits = asort ($fruits);
printr ($fruits);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The function asort() sorts the array in ascending order, except that the key/value corresponding is maintained.
38
What will be the output of the following PHP code?
<?php
$arr = array ("picture1.JPG", "picture2.jpg", "Picture10.jpg", "picture20.jpg");
sort($arr);
print_r($arr);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
While sorting each character is compared with the others and sorted using ascii values therefore we the sorted array to be like option c.
39
What will be the output of the following PHP code?
<?php
$face = array ("A", "J", "Q", "K");
$number = array ("2","3","4", "5", "6", "7", "8", "9", "10");
$cards = array_merge ($face, $number);
print_r ($cards);
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The resulting array will begin with the first input array parameter, appending each subsequent array parameter in the order of appearance.
40
What will be the output of the following PHP code?
<?php
$fruits = array ("apple", "mango", "peach", "pear", "orange");
$subset = array_slice ($fruits, 2);
print_r ($subset);
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The array_slice() function returns a section of an array based on a starting and ending offset value.