PHP

PHP

Arrays has 18 Questions
PHP's numerically indexed array begin with position __.

1
2
0
-1
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"?);

iii) and iv)
ii) and iii)
Only i)
ii), iii) and iv)
What will be the output of the following php code?
  1.     <?php
  2.     $states = array("karnataka" => array
  3.     ( "population" => "11,35,000", "captial" => "Bangalore"),
  4.     "Tamil Nadu" => array( "population" => "17,90,000",
  5.     "captial" => "Chennai") );
  6.     echo $states["karnataka"]["population"];
  7.     ?>

karnataka 11,35,000
11,35,000
population 11,35,000
karnataka population
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()
Which in-built function will add a value to the end of an array?

array_unshift()
into_array()
inend_array()
array_push()
What will be the output of the following PHP code?
  1.     <?php
  2.     $state = array ("Karnataka", "Goa", "Tamil Nadu",
  3.     "Andhra Pradesh");
  4.     echo (array_search ("Tamil Nadu", $state) );
  5.     ?>

True
1
False
2
What will be the output of the following PHP code?
  1.     <?php
  2.     $fruits = array ("apple", "orange", "banana");
  3.     echo (next($fruits));	
  4.     echo (next($fruits));
  5.     ?>

orangebanana
appleorange
orangeorange
appleapple
Which function can be used to move the pointer to the previous array position?

last()
before()
prev()
previous()
Which function returns an array consisting of associative key/value pairs?

count()
array_count()
array_count_values()
count_values()
What will be the output of the following PHP code?
  1.     <?php
  2.     $fruits = array ("mango", "apple", "pear", "peach");
  3.     $fruits = array_flip($fruits);
  4.     echo ($fruits[0]);
  5.     ?>

mango
Error
peach
0
Which of the functions is used to sort an array in descending order?

sort()
asort()
rsort()
dsort()
What will be the output of the following PHP code?
  1.     <?php
  2.     $fruits = array ("mango", "apple", "peach", "pear");
  3.     $fruits = asort ($fruits);
  4.     printr ($fruits);
  5.     ?>

Array ( [1] => apple [0] => mango [2] => peach [3] => pear )
Array ( [0] => apple [1] => mango [2] => peach [3] => pear )
Error
Array ( [1] => apple [0] => mango [3] => peach [2] => pear )
What will be the output of the following PHP code?
  1.     <?php
  2.     $array1 = array ("KA", "LA", "CA", "MA", "TA");
  3.     $array2 = array ("KA", "IA", "CA", "GA", "TA");
  4.     $inter = array_intersect ($array1, $array2);
  5.     print_r ($inter);
  6.     ?>

Array ( [0] => KA [1] => LA [2] => CA [3] => MA [4] => TA [5] => IA [6] => GA )
Array ( [0] => KA [2] => CA [4] => TA )
Array ( [1] => IA [3] => GA )
Array ( [1] => LA [3] => MA )
What will be the output of the following PHP code?
  1.     <?php
  2.     $number = array ("4", "hello", 2);
  3.     echo (array_sum ($number));
  4.     ?>

4hello2
4
2
6
What will be the output of the following PHP code?
  1.     <?php
  2.     $fruits = array ("apple", "mango", "peach", "pear",
  3.     "orange");
  4.     $subset = array_slice ($fruits, 2);
  5.     print_r ($subset);
  6.     ?>

Array ( [0] => peach )
Array ( [0] => apple [1] => mango [2] => peach )
Array ( [0] => apple [1] => mango )
Array ( [0] => peach [1] => pear [2] => orange )
What will be the output of the following PHP code?
  1.     <?php
  2.     $face = array ("A", "J", "Q", "K");
  3.     $number = array ("2","3","4", "5", "6", "7", "8", "9", "10");
  4.     $cards = array_merge ($face, $number);
  5.     print_r ($cards);
  6.     ?>

Array ( [0] => A [1] => J [2] => Q [3] => K [4] => 2 [5] => 3 [6] => 4 [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
Array ( [0] => A [1] => 2 [2] => J [3] => 3 [4] => Q [5] => 4 [6] => K [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
Error
Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9] => A [10] => J [11] => Q [12] => K )
Say in the above question you need to get the array sorted in the manner we humans would have done it i.e picture1 then picture2 etc.. Which of the following function should be used?

dsort()
casesort()
natcasesort()
naturalsort()
What will be the output of the following PHP code?
  1.     <?php
  2.     $fruits = array ("apple", "mango", "peach", "pear",
  3.     "orange");
  4.     $subset = array_splice ($fruits, 2);
  5.     print_r ($fruits);
  6.     ?>

Error
Array ( [0] => apple [1] => mango [2] => peach )
Array ( [0] => apple [1] => mango )
Array ( [0] => pear [1] => orange )