Skip to content

Instantly share code, notes, and snippets.

@michaeldyrynda
Created January 16, 2015 00:43
Show Gist options
  • Save michaeldyrynda/d3bb436f19cbdabaa6b7 to your computer and use it in GitHub Desktop.
Save michaeldyrynda/d3bb436f19cbdabaa6b7 to your computer and use it in GitHub Desktop.
Integer? Maybe. This has been done over and over, but it's still annoying as hell.
<?php
int 12345
string '12345'
filter_var(12345, FILTER_VALIDATE_INT); // true
filter_var('12456', FILTER_VALIDATE_INT); // true
'this is a string'
'12345'
'1' + 1 // 2
1 == 1 // true
'1' == 1 // true
'1' === 1 // false
date('N', $date) // string '7'
date('N', $date) === 7 // false
(int) date('N', $date) === 7 // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment