Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The term "haystack" in the context of PHP

There are a few PHP functions (such as strstr, strpos and strrchr) that accept a parameter named $haystack. Where does this name come from?

enter image description here

like image 803
Emanuil Rusev Avatar asked Jan 26 '11 19:01

Emanuil Rusev


2 Answers

It comes from the idiom "needle in a haystack". The needle is the item you're searching for (in this case the substring, or search string), the haystack is what the needle is located within (in this case the input string).

Edit (pst - to visualize answer):

needle stack

like image 190
BoltClock Avatar answered Oct 13 '22 12:10

BoltClock


Finding a needle in a haystack. You are looking for a substring in a bigger string.

like image 29
Gazler Avatar answered Oct 13 '22 12:10

Gazler