Home > PHP & Programming > Quizzes > PHP Programming Basics Practice Test: PHP Arrays and Functions
PHP Programming Basics Practice Test: PHP Arrays and Functions
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “What will be the output of the following PHP code?”
Quiz on arrays in PHP and other in built functions of PHP. In PHP, an array is a fundamental data structure that stores and organizes multiple values under a single variable. It provides a convenient way to manage and manipulate collections of data, making it an essential concept in PHP development.  PHP has over 1,000 built-in functions that can be called directly from within a script. These functions are pre-defined and included within the core PHP language. They can be used without any special requirements or additional installation.  Some examples of built-in functions include: String... Show more
PHP Programming Basics Practice Test: PHP Arrays and Functions
Time left 00:00
25 Questions

1. What will be the output of the following PHP code?

$age = array("Harry" => "21", "Ron" => "23","Malfoy" => "21");
array_pop($age);
print_r(array_change_key_case($age, CASE_UPPER));
?>
2. What will be the output of the following PHP code?

function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
b();
a();
?>
3. A function in PHP which starts with __ (double underscore) is known as __________
4. How to define a function in PHP?
5. What will be the output of the following PHP code?

$a = array("red", "green", "blue");
array_pop($a);
print_r($a);
?>
6. What will be the output of the following PHP code?

$city_west = array("NYC", "London");
$city_east = array("Mumbai", "Beijing");
print_r(array_replace($city_west, $city_east));
?>
7. What will be the output of the following PHP code?

$op2 = "blabla";
function foo($op1)
{
echo $op1;
echo $op2;
}
foo("hello");
?>
8. Which of the following function is used to get the value of the previous element in an array?
9. What will be the output of the following PHP code?

$fruits = array ("apple", "mango", "peach", "pear",
"orange");
$subset = array_splice ($fruits, 2);
print_r ($fruits);
?>
10. Type Hinting was introduced in which version of PHP?
11. What will be the output of the following PHP code?

$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
$result = array_flip($a1);
print_r($result);
?>
12. Which of the following are correct ways of creating an array?
i) state[0] = "karnataka";
ii) $state[] = array("karnataka");
iii) $state[0] = "karnataka";
iv) $state = array("karnataka");
13. What will be the output of the following PHP code?

$fruits = array ("mango", "apple", "pear", "peach");
$fruits = array_flip($fruits);
echo ($fruits[0]);
?>
14. Which of the following PHP function will return true if a variable is an array or false if it is not an array?
15. What will be the output of the following PHP code?

$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);
?>
16. Which in-built function will add a value to the end of an array?
17. What will be the output of the following PHP code?

$a1 = array("red", "green");
$a2 = array("blue", "yellow");
$a3 = array_merge($a1, $a2);
$a4 = array("a", "b", "c", "d");
$a = array_combine($a4, $a3);
print_r($a);
?>
18. What will be the output of the following PHP code?

$place = array("NYC", "LA", "Paris");
array_pop($place);
$place1 = array("Paris");
$place = array_merge($place, $place1);
print_r($place);
?>
19. What will be the output of the following PHP code?

$cars = array("Volvo", "BMW", "Toyota", "Honda", "Mercedes", "Opel");
print_r(array_chunk($cars, 2));
?>
20. What will be the output of the following PHP code?

$array = array("red", "green");
array_push($array, "blue", "yellow");
print_r($array);
?>
21. What will be the output of the following PHP code?
$fruits = array ("mango", "apple", "peach", "pear");
$fruits = asort ($fruits);
printr ($fruits);
?>
22. Which of the following are valid function names?
i) function()
ii) €()
iii) .function()
iv) $function()
23. What will be the output of the following PHP code?
echo chr(52);
?>
24. What will be the output of the following PHP code?

$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);
?>
25. What will be the output of the following PHP code?

$number = range(0, 5);
print_r ($number);
?>