$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 & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.