4 ms·
One can sort out a lot of PHP parameter order inconsistencies remembering that if $haystack is an array then it's the second parameter after $needle. For string
by z92 8y ago
One can sort out a lot of PHP parameter order inconsistencies remembering that if $haystack is an array then it's the second parameter after $needle. For string it's the opposite.
array_exists($needle, $haystack);
But
substr($haystack, $needle);
- kijin 8y agoYou're probably thinking of in_array() and strpos(). Yeah, the names themselves are confusing, not just the order of arguments. I wish PHP was fully object-oriented so you could call a method on any array, string, or number like in JavaScript. $haystack->contains($needle) is so much more consistent! That would eliminate the need for most of those confusing global functions, which can then be safely deprecated.