Sometimes, you may wish to check a POST variable and when it is not set then get a default value. The first approach could be:
$var = isset( $_POST[ 'var_post' ] ) ? $_POST[ 'var_post' ] : 'default';
However, you could use a simple function to do that:
/**
* Check a POST and use default value when it is not set.
*
* @param $id_post POST key
* @param $default Optional. Default value when is not set.
*/
function isset_post( $id_post, $default = '' ) {
return( isset( $_POST[ $id_post] ) ? $_POST[ $id_post] : $default );
}
For example:
$var = isset_post( 'product' );
// or
$var = isset_post( 'product', 'phone' );