That's because it's a string. You're just putting the string "screen" => "WOOOOORK", "id" => "6" as the first element of the array. What you need to do is to manually parse it in one of two ways.
-
Explode on the "," so that every element is in {var}={val} format (or just a variable name).
-
Use [man]eval/man to evaluate the code to an array.
Since #2 uses the eval method (which in 90% of cases is the wrong way to do it), I'll give you an example of #1.
<?php
$_GET = array(
'screen' => 'Something Else',
'id' => 72,
'var' => 'some value',
'test' => "{something:'json encoded'}"
);
$change = "screen=WOOOOORK,id=6,var";
function url($change=false)
{
$url = 'http://localhost/game/game.php?';
$tmp = explode(',', $change);
$newChange = array();
foreach($tmp as $item)
{
$vals = explode('=', $item);
$newChange[$vals[0]] = (isset($vals[1]) ? $vals[1] : null);
}
foreach($_GET as $var=>$val)
{
if(array_key_exists($var, $newChange))
{
$val = $newChange[$var];
}
$url .= $var .'='.urlencode($val).'&';
}
$url = substr($url, 0, -1); // Strip the trailing '&'
return $url;
}
echo url($change)."\n";
I had to manually set $_GET; however, this is just a test case. It will spit out:
http://localhost/game/game.php?screen=WOOOOORK&id=6&var=&test=%7Bsomething%3A%27json+encoded%27%7D
Hope that helps.