Haystack-Needle-Sheet

Permanent Link: Haystack-Needle-Sheet 4. August 2009 RSS Feed for comments on RSS-Feed für Kommentare zu: Haystack-Needle-Sheet comments feed

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.

You can download the Haystack-Needle-Sheet here

4 comments

ellisgls Gravatar

ellisgl
04.08.2009, 14:54 o'clock

Wish it had a short description about the function for cross ref. =)

Dominik Jungowskis Gravatar

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 Wellss Gravatar

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.

FloHs Gravatar

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').

Write a comment

(will not be published)