$output=array_pop($input);
array_pop()
total elements of the array reduces by one. All numerical array keys remain same as last element is removed. Literal keys remain same.
$input=array('One','Two','Three','Four');
$output=array_pop($input);
echo $output;// Output : Four
echo "<br><br>";
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
Output of above code is here( $output gets the last element Four )
Four
0 -> One
1 -> Two
2 -> Three
$input=array('Fruits1' =>'Banana','Fruits2'=>'Mango','Fruits3'=>'Apple','Fruits4'=>'Grapes');
$output=array_pop($input);
echo $output;// Output : Grapes
echo "<br><br>";
while (list ($key, $val) = each ($input)) {
echo "$key -> $val <br>";
}
Output is here, ( $output gets the first element Grapes)
Grapes
Fruits1 -> Banana
Fruits2 -> Mango
Fruits3 -> Apple
$input=array('Fruits1' =>'Banana','Fruits2'=>'Mango','Fruits3'=>'Apple','Fruits4'=>'Grapes');
end($input);
echo current($input);
echo "<br>";
$output=array_pop($input);
end($input);
echo current($input);
Output is here.( The last element is changed from Grapes to Apple)
Grapes
Apple
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.