Haystack-Needle-Sheet
Surely every PHP developer has come across the PHP Haystack-Needle-Phenomenon: Mostly the parameter order is $haystack, $needle but in some cases it's $needle, $haystack for no apparent reason. Trying to find regularities I found out that it's only the array functions that use needle, haystack instead of haystack, needle - assuming I didn't forget any functions. For that reason I created a Haystack-Needle-Sheet, which shows you which function uses haystack, needle and which one needle, haystack.
If you should come across functions that are missing on this list, please let me know.
4 comments
Dominik Jungowski
07.08.2009, 10:35 o'clock
That's a good idea actually. I think I will update the sheet some time soon adding a short description
John Wells
11.08.2009, 09:06 o'clock
explode() and implode() are also useful to add – they are in effect $needle $haystack order.
In addition, str_replace, and all the regex functions, are $needle, $replacement, $haystack order.
If there's one thing PHP lacks, it's consistency. Fortunately the online documentation is excellent and can be pulled up in seconds. However, for that reason, I find it difficult to code in PHP without an internet connection.
FloH
14.09.2009, 19:34 o'clock
Not exactly "$needle, $haystack" but the example for inconsistency that I always give is array_map('callback',$array) and array_filter($array,'callback').
4. August 2009
comments feed
recent posts
ellisgl
04.08.2009, 14:54 o'clock
Wish it had a short description about the function for cross ref. =)