Re: how a function 'return' statement works

From: Date: Thu, 14 Feb 2002 20:40:12 +0000
Subject: Re: how a function 'return' statement works
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-84817@lists.php.net to get a copy of this message
On Thursday, February 14, 2002, at 02:32 PM, Lars Torben Wilson wrote:
I think what you're trying to do is return one particular element out of the array. If that's the case, just use something like: return $current_page_name[-1] to return the last element in the array.
I do not know where this came from, but it just ain't so.
Torben, I just got this message now (where you explained a better way to do it). I got a lot of feedback on this, and I feel even worse than before for not realizing that I was trying to display the value of an array element without specifying its key! and then this gem up top here got me thinking I could shortcut the "array_slice($current_page_name, -1, 1)" to get the last element. The substr trick works too, but I'm glad i was able to do it my way too. here is the final function: # =============================================================== # get_current_page_name() # --------------------------------------------------------------- # Returns the current document # Arguments # ----------- # no arguments # =============================================================== function get_current_page_name() { $current_page = $_SERVER['PHP_SELF']; $current_page_name = explode("/", $current_page); $pagename = array_slice($current_page_name, -1, 1); return $pagename[0]; } ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com

« previous php.general (#84817) next »