note 99699 modified in function.http-build-query by danbrown

From: Date: Tue, 31 Aug 2010 14:52:09 +0000
Subject: note 99699 modified in function.http-build-query by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172199@lists.php.net to get a copy of this message
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> */ ?> --was-- 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> */ http://php.net/manual/en/function.http-build-query.php

« previous php.notes (#172199) next »