Created
June 19, 2015 09:31
-
-
Save marcojetson/6ecb171289be40454ade to your computer and use it in GitHub Desktop.
PHP API is weird
This file contains 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 | |
/** | |
* Checks if a value exists in an array | |
* | |
* @param array $haystack | |
* @param mixed $needle | |
* @param bool $strict | |
* @return bool | |
*/ | |
function inarray(array $haystack, $needle, $strict = false) { | |
return in_array($needle, $haystack, $strict); | |
} | |
/** | |
* Find the position of the first occurrence of a substring in a string | |
* | |
* @param mixed $needle | |
* @param string $haystack | |
* @param int $offset | |
* @return bool | |
*/ | |
function str_pos($needle, $haystack, $offset = 0) { | |
return strpos($haystack, $needle, $offset); | |
} | |
assert(in_array('a', ['a', 'b', 'c']) === inarray(['a', 'b', 'c'], 'a')); | |
assert(strpos('marco', 'a') === str_pos('a', 'marco')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment