Vidyalelo
PHP · all questions

Arrays
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

53

Questions

1/3

Page

Pick an option on a question to see the right answer and solution.

PHP’s numerically indexed array begin with position ______.

Select an option to see the answer and solution.

Which of the following are correct ways of creating an array?
1. state[0] = “karnataka”;
2. $state[] = array(“karnataka”);
3. $state[0] = “karnataka”;
4. $state = array(“karnataka”);

Select an option to see the answer and solution.

What will be the output of the following php code?
<?php
$states = array("karnataka" => array( "population" => "11,35,000", "captial" => "Bangalore"),"Tamil Nadu" => array( "population" => "17,90,000","captial" => "Chennai") );
echo $states["karnataka"]["population"];
?>

Select an option to see the answer and solution.

Which function will return true if a variable is an array or false if it is not?

Select an option to see the answer and solution.

Which in-built function will add a value to the end of an array?

Select an option to see the answer and solution.

What will be the output of the following PHP code?
<?php
$state = array ("Karnataka", "Goa", "Tamil Nadu", "Andhra Pradesh");
echo (array_search ("Tamil Nadu", $state) );
?>

Select an option to see the answer and solution.

What will be the output of the following PHP code?
<?php
$fruits = array ("apple", "orange", "banana");
echo (next($fruits));	
echo (next($fruits));
?>

Select an option to see the answer and solution.

Which function can be used to move the pointer to the previous array position?

Select an option to see the answer and solution.

What will be the output of the following PHP code?
<?php
$fruits = array ("apple", "orange", array ("pear", "mango"), "banana");
echo (count($fruits, 1));
?>

Select an option to see the answer and solution.

Which function returns an array consisting of associative key/value pairs?

Select an option to see the answer and solution.

What will be the output of the following PHP code?
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . cars[1] . " and " . $cars[0] . ".";
?>

Select an option to see the answer and solution.

What will be the output of the following PHP code?
<?php
$fname = array("Peter", "Ben", "Joe");
$age = array("35", "37", "43");
age, $fname);
print_r($c);
?>

Select an option to see the answer and solution.

What will be the output of the following PHP code?
<?php
$a=array("A","Cat","Dog","A","Dog");
$b=array("A","A","Cat","A","Tiger");
a,$b);
print_r(array_count_values($c));
?>

Select an option to see the answer and solution.

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", "h" => "orange");
$a3 = array("i" => "orange");
a2, $a3);
a4, $a2);
print_r($result);
?>

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following PHP code?
<?php
$names = array("Sam", "Bob", "Jack");
echo names[1] . " and " . $names[1] . ".";
?>

Select an option to see the answer and solution.

What will be the output of the following PHP code?
<?php
$names = array("Sam", "Bob", "Jack");
echo names[1] . " and " . brother;
?>

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following PHP code ?
<?php
$a1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow");
a1);
print_r($result);
?>

Select an option to see the answer and solution.