Validate input of month/year, otherwise set it to current month/year Is there a cleaner way of doing this? I'm using filter_input to first check for valid input, then using it again to assign the variable. Also, my condition in if/else seems quite long.

$optionsMonth = array('options'=&gt;array('min_range'=&gt;1, 'max_range'=&gt;12));
$optionsYear = array('options'=&gt;array('min_range'=&gt;1900, 'max_range'=&gt;9999));

if ((filter_input(INPUT_GET, 'month', FILTER_VALIDATE_INT, $optionsMonth))&amp;&amp;(filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT, $optionsYear))){
    $month = filter_input(INPUT_GET, 'month', FILTER_VALIDATE_INT, $optionsMonth );
    $year = filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT, $optionsYear);
} else {
    $datetime = new Datetime('NOW');
    $month = $datetime-&gt;format('m');
    $year = $datetime-&gt;format('Y');
}
You may be over thinking it.  It's actually very simple.

The only ambiguous thing is if the year is two digits.  In most cases a two digit year can be fixed like this.  I believe in your use the month and year will be all be future and nothing from the 1900s. 

if (intval($optionsYear) &lt; 100){$optionsYear  = '20' . $optionsYear;}


Then to finish up:

$date = strtotime("$optionsYear-$optionsMonth-13"); // yyyy-mm-dd
if ($date){  // test validity, will be false if invalid
  $month = date('m',$date);  // invalid, use today's month and year.
  $year = date('Y',$date); 
}
else{
  $month = date('m');  // valid numbers entered
  $year = date('Y'); 
}


Because the day of the month is no an issue I used 13.  Not that it would but in dates the month and day can cause problems.  By using a day of 13 it cannot be confused with a month.  If a date were entered as 13/4/2015, it would not be difficult to understand 13 is a day and 4 is a month. Oct, Nov, Dec would still be ambiguous if entered as 10, 11, or 12.