Question 1. 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”);
3 and 4
2 and 3
Only 1
2, 3 and 4
Explanation:-
Answer: Option A. -> 3 and 4 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.
Question 2. PHP’s numerically indexed array begin with position ______.
1
2
0
-1
Explanation:-
Answer: Option C. -> 0 Like many programming languages, the first element of an array has an index value of 0.
Question 3. What will be the output of the following php code?
karnataka 11,35,000
11,35,000
population 11,35,000
karnataka population
Explanation:-
Answer: Option B. -> 11,35,000 Treat states as a multidimensional array and accordingly traverse it to get the value.
Question 4. Which function will return true if a variable is an array or false if it is not?
this_array()
is_array()
do_array()
in_array()
Explanation:-
Answer: Option B. -> is_array() A built-in function, is_array(), is available for testing an array. Its prototype follows: boolean is_array(mixed variable).
Question 5. Which in-built function will add a value to the end of an array?
array_unshift()
into_array()
inend_array()
array_push()
Explanation:-
Answer: Option D. -> array_push() 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.
Question 6. What function computes the difference of arrays?
array_diff
diff_array
arrays_diff
diff_arrays
Explanation:-
Answer: Option A. -> array_diff
Question 7. What array will you get if you convert an object to an array?
An array with properties of that object as the array's elements
An array with properties of that array as the object's elements
An array with properties of that object as the Key elements
An array with keys of that object as the array's elements
Explanation:-
Answer: Option A. -> An array with properties of that object as the array's elements
Question 8. What functions count elements in an array? 1. count 2. Sizeof 3. Array_Count 4. Count_array
Option 2 and 4
Option 1 and 2
Option 3 and 4
Option 1 and 4
Explanation:-
Answer: Option B. -> Option 1 and 2
Question 9. What will be the output of the following PHP code?
I like Volvo, Toyota and BMW
I like Volvo, BMW and Toyota
I like BMW, Volvo and Toyota
I like Toyota, BMW and Volvo
Explanation:-
Answer: Option D. -> I like Toyota, BMW and Volvo The order of elements defined.
Question 10. What will be the output of the following PHP code?
Array ( Peter Ben Joe )
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
Array ( 35 37 43 )
Array ( [35] => Peter [37] => Ben [43] => Joe )
Explanation:-
Answer: Option D. -> Array ( [35] => Peter [37] => Ben [43] => Joe ) Here “keys” array is $age and “values” array is $fname.