Created
March 18, 2012 00:20
-
-
Save sbisbee/2066956 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = array("bwah"); | |
var_dump(in_array(0, $arr, true)); //false | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach($array as $value) | |
if(($strict && $value === $cmpTo) || (!$strict && $value == $cmpTo)) | |
return true; | |
return false; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = array("foo" => "bar"); | |
var_dump(in_array("bar", $arr)); //true | |
var_dump(in_array("foo", $arr)); //false | |
$arr = array("hi", "there"); | |
var_dump(in_array(0, $arr)); //true | |
var_dump(in_array(1, $arr)); //false | |
$arr = array(0 => "hi", 1 => "there"); | |
ar_dump(in_array(0, $arr)); //true | |
ar_dump(in_array(1, $arr)); //false | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach((array) $items as $k => $v) | |
echo (in_array($k, $dateFields) ? date('F jS, Y', $v) : $v; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = array("bwah"); | |
var_dump(in_array((bool) 0, $arr)); //false | |
var_dump(in_array((int) 0, $arr)); //true | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = array(); | |
var_dump(in_array("a", $arr)); //false | |
var_dump(in_array(0, $arr)); //false | |
var_dump(in_array(true, $arr)); //false | |
$arr = array("bwah"); | |
var_dump(in_array("a", $arr)); //false | |
var_dump(in_array(0, $arr)); //TRUE - OMG WTF?! | |
var_dump(in_array((float) 0.0, $arr)); //TRUE - OMG WTF?! | |
var_dump(in_array(true, $arr)); //true - makes some sense, since ("a string" == true) in PHP | |
var_dump(in_array(false, $arr)); //false | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment