How to Test a Date for Validity in PHP

Needed a function to test if a date was valid in PHP. This function does that but it also requires an expected date format.

Example

Output

bool(true)
bool(false)
bool(true)
bool(false)