Forum : How do I remove and view the last element of an array?
Brief description  about Online courses   join in Online courses
View Abhijit  Paul 's Profile

How do I remove and view the last element of an array?

How do I remove and view the last element of an array????????
Asked by Abhijit Paul | Mar 17, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
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 $discard\n\n";
$sentence = implode(" ",$values);
echo "$sentence";
?>
Which gives us the following output:
Bye bye to Finish
I Like Sentences That Don't
Mar 17, 2010