Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Rifqi Fahmi
Rifqi Fahmi
23,164 Points

what is 'needle' and 'haystack' in PHP ??

I found that in php manual there are $needle and $haystack such as

<?php string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] ) ?>

Can anyone explain what are needle and haystack mean ??? Thankyou :D

1 Answer

Sanjay Nair
PLUS
Sanjay Nair
Courses Plus Student 2,477 Points

Rifqi Fahmi $haystack is the search array or the char sequence. $needle -- is what you want to search in the char sequence $haystack.

Check the example on php manual for more clarity: http://php.net/manual/en/function.strstr.php

<?php $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // prints @example.com

$user = strstr($email, '@', true); // As of PHP 5.3.0 echo $user; // prints name ?>