Website And Mobile Application Development Company In India



An array is a special variable, which can hold more than one value at a time.

Array Syntax: $arrayName = array ("value1","value2","value3");

In PHP, there are three types of arrays:

  • Indexed arrays or Numeric arrays - Arrays with numeric index
  • Associative arrays - Arrays with named keys
  • Multidimensional arrays - Arrays containing one or more arrays

1) array_shift Function:

The array_shift function removes the first element of an array from the array and stores it in the receiving variable.

$myarray = array("Apples", "Oranges", "Pears");
$fruit = array_shift($myarray);  
echo $fruit; // Apples
print_r($myarray);  // Oranges and Pears will be displayed without Apples

2) array_unshift Function:

Prepend one or more elements to the beginning of an array.

$queue = array("orange", "banana");
array_unshift($queue, "apple", "raspberry");