unset() from array versus if inside loop?

MistyBlue

New Member
I'm making a pagination script. As part of it, it will need to reconstruct the query string, minus \[code\]$_GET['page']\[/code\].This is option 1:\[code\]#reconstruct the GETs minus $_GET['page']$vars = $_GET;unset($vars['page']);$queryString = '';foreach ($vars as $k=>$v){ $queryString .= '&'.$k.'='.$v;}\[/code\]This is option 2:\[code\]$vars = $_GET;$queryString = '';foreach ($vars as $k=>$v){ if ($k !== 'page'){ $queryString .= '&'.$k.'='.$v; }}\[/code\]Is one better than the other in terms of either speed or good practice? Presumably \[code\]unset\[/code\] would be marginally quicker, as it would stop as soon as it found what it was looking for whereas the other would perform the \[code\]if\[/code\] for every loop?Additionally, when initializing the \[code\]$queryString\[/code\] is there a reason to choose \[code\]NULL\[/code\] over empty string or does it make no difference to anything?
 
Back
Top