PHP Array Interview Questions & Answers

PHP Array Interview Questions & Answers list

Here, you can read about PHP Array related Interview Questions & Answers – This list contains popular & frequently asked interview questions related to PHP Arrays along with answers – Find PHP Array FAQs for Job Preparation.

What are the different PHP functions to sort an array?

  • asort()
  • arsort()
  • ksort()
  • krsort()
  • uksort()
  • sort()
  • nasort()
  • rsort()

For more details: http://tutorialsclass.com/learn/php/php-array-functions


PHP’s numerically indexed array begin with which position?

PHP Indexed array begins with position 0.
For example if: $array=array(15,80,67,33); Then these elements will have following positions:
$array[0]=10 (This is beginning position 0 not 1)
$array[1]=89
$array[2]=34
$array[3]=67


Which PHP function inserts an element to the end of an array?

PHP array_push() function is used to insert one or more elements to the end of an array.


How many types of arrays are available in PHP?

There are three types of array available in PHP.

  1. Numeric (Indexed) array
  2. Associative array
  3. Multidimensional array

Learn more about array with examples in PHP Array Tutorial


What is the use of array_chunk() function in PHP?

The array_chunk() function is used to split an array into parts or chunks of new arrays. Example: array_chunk(array,size);

The first parameter specifies an array and the second parameter defines the size of each chunk.


What is the use of in_array() function in PHP?

The in_array() function is used to search for the given string in an array. It returns TRUE if the given string is found in the array, and FALSE otherwise.


Which PHP function counts all the values of an array?

array_count_values() function is used to count all the values of an array. PHP array_count_values() returns an array that has the values of given array as keys and their frequency in the array as values.