ExamVeda
Login
Home
1
PHP’s numerically indexed array begin with position ______.
Discuss
Answer & Solution
Answer: Option C
Solution:
Like many programming languages, the first element of an array has an index value of 0.
2
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”);
Discuss
Answer & Solution
Answer: Option A
Solution:
A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when you use the array() constructor.
3
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"];
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Treat states as a multidimensional array and accordingly traverse it to get the value.
4
Which function will return true if a variable is an array or false if it is not?
Discuss
Answer & Solution
Answer: Option B
Solution:
A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean is_array(mixed variable).
5
Which in-built function will add a value to the end of an array?
Discuss
Answer & Solution
Answer: Option D
Solution:
array_push adds a value to the end of an array, returning the total count of elementsin the array after the new value has been added.
6
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) );
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The array_search() function searches an array for a specified value, returning its key if located and FALSE otherwise.
7
What will be the output of the following PHP code?
<?php
$fruits = array ("apple", "orange", "banana");
echo (next($fruits));	
echo (next($fruits));
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The next() function returns the array value residing at the position immediately following that of the current array pointer.
8
Which function can be used to move the pointer to the previous array position?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
9
What will be the output of the following PHP code?
<?php
$fruits = array ("apple", "orange", array ("pear", "mango"), "banana");
echo (count($fruits, 1));
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The array entity holding pear and mango is counted as an item, just as its contents are.
10
Which function returns an array consisting of associative key/value pairs?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board