Skip to content

Instantly share code, notes, and snippets.

@marcojetson
Created June 19, 2015 09:31
Show Gist options
  • Save marcojetson/6ecb171289be40454ade to your computer and use it in GitHub Desktop.
Save marcojetson/6ecb171289be40454ade to your computer and use it in GitHub Desktop.
PHP API is weird
<?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