note 100891 added to control-structures.foreach

From: Date: Sat, 13 Nov 2010 06:37:06 +0000
Subject: note 100891 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-173991@lists.php.net to get a copy of this message
This is an example of the use of the second, minor case of foreach. A useful script that returns the relative URL of the current page with the current "GET data". function getCurrentURL() { $currentURL = basename($_SERVER["PHP_SELF"]); $i = 0; foreach($_GET as $key => $value) { $i++; if($i == 1) { $currentURL .= "?"; } else { $currentURL .= "&"; } $currentURL .= $key."=".$value; } return $currentURL; } Note that most of the time basename($_SERVER["REQUEST_URI"] is enough for this task as well, but if in the browsers's address bar is only http://something.com/ instead of http://something.com/index.php displayed, than basename($_SERVER["REQUEST_URI"] fails. ---- Server IP: 69.147.83.197 Probable Submitter: 89.132.197.59 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/100891 Del: integrated -- https://master.php.net/note/delete/100891/integrated Del: useless -- https://master.php.net/note/delete/100891/useless Del: bad code -- https://master.php.net/note/delete/100891/bad+code Del: spam -- https://master.php.net/note/delete/100891/spam Del: non-english -- https://master.php.net/note/delete/100891/non-english Del: in docs -- https://master.php.net/note/delete/100891/in+docs Del: other reasons-- https://master.php.net/note/delete/100891 Reject -- https://master.php.net/note/reject/100891 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173991) next »