Don't store variable if not set
function append_URL( $link, $sort ) {
$sort = $_GET['sort'];
if ( isset($sort) ) {
$link = add_query_arg( 'sort', $sort, $link );
}
return $link;
}
I get this notice Undefined index: sort
when no sort
parameter exists. What is the best way to check if the sort
param exists before creating the $开发者_如何转开发sort
variable?
$sort = array_key_exists('sort', $_GET) ? $_GET['sort'] : null;
Also, if you're just setting the $sort value from the $_GET, why do you pass it in as an argument to your function? It seems redundant.
if (isset($_GET['sort']))
精彩评论