note 99699 deleted from function.http-build-query by hholzgra

From: Date: Thu, 02 Aug 2012 13:42:08 +0000
Subject: note 99699 deleted from function.http-build-query by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189780@lists.php.net to get a copy of this message
Note Submitter: boukeversteegh at gmail dot com ---- When building querystrings, you often need to pass original arguments into the new querystring. An easy way to combine a bunch of default values, plus some overwrites into a new array, is using the Array operator +. This works great with http_build_query: <?php # Suppose $_GET is set like this. # or put some default values in here. $_GET = Array( 'page' => 'item', 'id' => 14, 'action' => 'view' ); $edit_url = http_build_query( Array( 'action' => 'edit' ) + $_GET ); echo "<a href=\"$edit_url\">Edit</a>"; /* Prints <a href="action=edit&page=item&id=14">Edit</a> */ ?>

« previous php.notes (#189780) next »