I don't have any real need for this, but is there a built in php function that will allow me to get the second value from the end of an array? Sort of like:
$end=array($arr, -1, 1);
I don't have any real need for this, but is there a built in php function that will allow me to get the second value from the end of an array? Sort of like:
$end=array($arr, -1, 1);
Last edited by james438; 05-25-2010 at 04:44 AM.
To choose the lesser of two evils is still to choose evil. My personal site
I've never used this but my guess is
$inversed = array_reverse($array);
$end = $inversed[1];
http://php.net/manual/en/function.array-reverse.php
Corrections to my coding/thoughts welcome.
james438 (05-25-2010)
Not exactly what I was looking for, but works just the same.
To choose the lesser of two evils is still to choose evil. My personal site
echo $array[count($array)-2];
(We subtract 2 because count returns a count from 1+ and array indexes range from 0+.)
BTW, this will return two errors (undefined index notice; error count's value is not an array) if you use it on a non-array or on an empty array. Check that first.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
james438 (05-25-2010)
nice, thanks for those answers. I was looking for something really simple like the answers you both gave.
To choose the lesser of two evils is still to choose evil. My personal site
Bookmarks