PHP array_shift() Function - Coding Tag

PHP array_shift() Function

Last Updated by Pooja Chikara

0 9583

array_shift() function of PHP used to shift the elements of array one position in left means it removes the initial or starting element of an array. If the array is an index array then it re-indexed the array from 0.

Syntax:

array_shift($array)

here,

$array is a PHP array.


Example 1:

<?php
$arr1=array(1,2,3,4,5,6,7,8);
echo "<pre>";
echo "Original array ";
print_r($arr1);
array_shift($arr1);
echo "After using array_shift() function ";
print_r($arr1);
?>

Output:

Ouput 1


Example 2:

<?php
$arr1=array("FRUIT1"=>"apple","FRUIT2"=>"Mango","FRUIT3"=>"banana","FRUIT4"=>"pear");
echo "<pre>";
echo "Original array";
print_r($arr1);
array_shift($arr1);
echo "After using array_shift() function";
print_r($arr1);
?>

Output:

Result - PHP Array Shift Function



Best WordPress Hosting


Share:

SSL for business, from $12.88


Leave a Reply


Comments
    Waiting for your comments

Coding Tag WhatsApp Chat
Coding Tag WhatsApp Chat