$count = count($_GET); $i = 0; foreach ($_GET as $key => $value) { if ($i == $count - 1) { $str .= $key . "=" . $value; } else { $str .= $key . "=" . $value . "&"; } $i ++; } echo $str;