Skip to content

Instantly share code, notes, and snippets.

@iluuu1994
Last active June 20, 2020 16:17
Show Gist options
  • Save iluuu1994/ba9187f44aecb32a2c59dec2639c5515 to your computer and use it in GitHub Desktop.
Save iluuu1994/ba9187f44aecb32a2c59dec2639c5515 to your computer and use it in GitHub Desktop.
=~= operator

=~= operator

// bool vs int
false =~= '' // true
false =~= '0' // false
false =~= 'false' // false
true =~= '1' // true
true =~= 'true' // false

// bool vs float
false =~= 0.0 // true
true =~= 1.0 // true
true =~= 1.1 // false

// bool vs string
false =~= '' // true
true =~= '1' // true
true =~= 'true' // false

// bool vs array
false =~= [] // false
true =~= ['1'] // true
true =~= ['foo'] // false

// bool vs object
// Always false
false =~= (new stdClass) // false
true =~= (new stdClass) // false

// bool vs null
// Always false
false =~= null // false
true =~= null // false

// int vs float
0 =~= 0.0 // true
0 =~= 0.1 // false
1 =~= 1.0 // true
2 =~= 2.0 // true

// int vs string
0 =~= '0' // true
0 =~= '' // false
1 =~= '1' // true
2 =~= '2' // true

// int vs array
0 =~= [] // false
0 =~= [0] // false
1 =~= [1] // true

// int vs object
// Always false
0 =~= (new stdClass) // false
1 =~= (new stdClass) // false

// int vs null
0 =~= null // false
1 =~= null // false

// float vs string
0.0 =~= '0.0' // false
0.0 =~= '0' // true
0.1 =~= '0.1' // true
1E+0 =~= '1' // true
1 =~= '1E+0' // false

// float vs array
0.0 =~= [] // false
0.0 =~= [0.0] // false
1.0 =~= [1.0] // true

// float vs object
// Always false
0.0 =~= (new stdClass) // false
1.0 =~= (new stdClass) // false

// float vs null
// Always false
0.0 =~= null // false
1.0 =~= null // false

// string vs array
'' =~= [] // false
'foo' =~= ['foo'] // false
'Array' =~= ['Array'] // true

// string vs object
// Always false
'' =~= (new stdClass) // false
'foo' =~= (new stdClass) // false

// string vs null
// Always false
'' =~= null // false
'foo' =~= null // false

// array vs object
// Always false
[] =~= (new stdClass) // false

// array vs null
// Always false
[] =~= null // false
['foo'] =~= null // false

// object vs null
// Always false
(new stdClass) =~= null // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment