$output=array_shift($input);
array_shift() total elements of the array reduces by one. All numerical array keys are re-indexed but literal keys remain same.
<?Php
$input=array('One','Two','Three','Four','Five');
$output=array_shift($input);
echo $output; // Output is One
echo "<br><br>";
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
?>
Output of above code is here( $output gets the first element One )
One
0 -> Two
1 -> Three
2 -> Four
3 -> Five
$input=array('Fruits1' =>'Banana','Fruits2'=>'Mango','Fruits3'=>'Apple','Fruits4'=>'Grapes');
$output=array_shift($input);
echo $output; // Output is Banana
echo "<br><br>";
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
Output is here, ( $output gets the first element Banana)
Banana
Fruits2 -> Mango
Fruits3 -> Apple
Fruits4 -> Grapes
$input=array('Fruits1' =>'Banana','Fruits2'=>'Mango','Fruits3'=>'Apple','Fruits4'=>'Grapes');
echo current($input);
echo "<br>";
$output=array_shift($input);
echo current($input);
Output is here.( The first element is changed from Banana to Mango)
Banana
Mango
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.