PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

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



More arrays PHP Questions

I want to invert my array, can I do this?
How do I remove an element from an array without changing the index values for the rest of the array?
How do I write my own sort function?
How can I display values in a two dimensional array?
How can I create an array of the letters of the alphabet?