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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -