12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Oct 1, 2021

How to get the value of query variables that have square brackets

Sridhar Katakam

There could be times when your website pages have query variables like this:


Ideally square brackets, [ and ] should be percent encoded as %5B and %5D but some systems like payment processors may take customer info and pass them to another page in your site with square brackets in the URL.

So if you wish to extract “Michael” from the example above and output it on the page having that query variable in its URL, here’s the PHP:

	$firstname = $_GET['customer']['firstname'];

	echo ( isset( $firstname ) ) ? $firstname : '';

If you wish to define a custom function that returns the above, here it is:

 * Returns the value of customer[firstname] URL parameter.
 * Sample usage: custom_get_query_var()
function custom_get_query_var() {	
	$firstname = $_GET['customer']['firstname'];

	return ( isset( $firstname ) ) ? $firstname : 'user';

This can be used with for example, PHP Function Return value of Dynamic Data feature in Oxygen to show the URL parameter value alongside other text.