$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 & 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.