How do I remove and view the last element of an array?
By Abhijit Paul
How do I remove and view the last element of an array????????
Teacher SiliconIndia replied to Abhijit Paul Wednesday, March 17, 2010
Hi Abhijit,
PHP expected you would want to do this quite often, and so there is a function that enables you to do just this. The function is called array_pop, and it works a little like this:
$values = array("I","Like","Sentences","That","Don't","Finish");
$discard = array_pop($values);
echo "Bye bye to $discardnn";
$sentence = implode(" ",$values);
echo "$sentence";
?>
Which gives us the following output:
Bye bye to Finish
I Like Sentences That Don't