PHP Array Interview Questions & Answers

Top 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 functions. Prepare for Jobs using our PHP FAQs list.

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 begins 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 the given array as keys and their frequency in the array as values.

How do you split a string into an array?

PHP explode() function is used to split the string into an array based on a certain character, substring or a symbol.

In this example, we have a string containing language list separated by a comma. Therefore, we can pass a comma character as a delimiter to break the string into the array.

<?php
// Take a string containing language list separated by a comma
$string = "PHP, HTML, CSS, JavaScript, MySQL";

// Use PHP explode function to extract all names separated by comma
$name_array = explode(",", $string);

// print array
print_r($name_array);
?>

Run example: https://paiza.io/projects/fXWTx9TVtj1FFvQPw75Wyg

Tutorials Class - Output Window

Array
(
[0] => PHP
[1] => HTML
[2] => CSS
[3] => JavaScript
[4] => MySQL
)