php - 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 notice undefined index: sort
when no sort
parameter exists. best way check if sort
param exists before creating $sort
variable?
$sort = array_key_exists('sort', $_get) ? $_get['sort'] : null;
also, if you're setting $sort value $_get, why pass in argument function? seems redundant.
Comments
Post a Comment