PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

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


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:

<?php

$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



Comment on this Question and Answer >>>

ASK A QUESTION

More arrays PHP Questions

How can I mix up the order of values in an array?

How can I sort an array keeping the correlation between the index and value?

How do I reverse sort an array by key?

How can I display a 2 dimensonal array?

how can you reset an array in PHP



Custom Search