RE: [PHP] how a function 'return' statement works

From: Date: Fri, 15 Feb 2002 13:49:59 +0000
Subject: RE: [PHP] how a function 'return' statement works
Groups: php.general 
Request: Send a blank email to php-general+get-84900@lists.php.net to get a copy of this message
> -----Original Message----- > From: Erik Price [mailto:pricee@hhbrown.com] > Sent: 14 February 2002 20:40 > > 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]; > } In place of the array_slice, why not use (the more readable) end($current_page_name)? And why not just return that directly, rather than assigning it to an intermediate variable that you're not using for anything else? Actually, I'd probably ask the same about all your intermediate results -- I'd probably have written this whole thing as a single statement, thus: return end(explode("/", $_SERVER['PHP_SELF'])); Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#84900) next »