Pretty neat code, but i usually don't like passing parameters by reference.
And i really can't see the use of the first "if ($found)" in
isInJaggedArrayHelper method... it's always going to be false when you first
call that method.

Anyway, here's my version of it. Tell me if it's any good.

On 1/27/07, Ala'a Ibrahim <[EMAIL PROTECTED]> wrote:
>
> Hi all,
> A colleague and I had written a code to search within a jagged array of
> strings, the problem is that I'm still not convinced that this is the best
> way to do it, so if anyone has a better idea please share it.
>
> Attached is the code, and a unit test for it using simpletest (
> http://simpletest.org/)
>
> --
>                                  Ala'a A. Ibrahim
> http://alaa-ibrahim.com/guru
> >
>
>


-- 
Al-Faisal El-Dajani
Phone: +962-7-77 799 781
P.O Box: 140056
11814 Amman, Jordan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Jordan PHP Users Group" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/JoPHP
http://Jolug.org/
-~----------~----~----~----~------~----~------~--~---

<?php
/**
 * ArraySearcher.php Created on 25-Jan-07
 * 
 * @author Ala'a A. Ibrahim <alaa_ibrahim at maktoob dot com>
 * @version 0.1.25.1.2007
 */
	/**
	 * An Array Search API
	 * 
	 * @author Moh'd. Abu Khamis <mohmad_abu_khamis at maktoob dot com>
	 * @author Ala'a A. Ibrahim <alaa_ibrahim at maktoob dot com>
	 * @version 0.1.25.1.2007
	 */
	class ArraySearcher {
		
		/**
		 * Search Within a Jagged Array of Strings
		 *
		 * @author Faisal Dajani <faisal dot dajani at google dot com>
		 * @param array $array
		 * @param string $needle
		 * @param bool $strict if true it would be case sensitive
		 * @return bool
		 */
		public function isInJaggedArray($array, $needle, $strict = false) {
			foreach ($array as $i) {
				if (is_array($i)) {
					if (isInJaggedArray($i, $needle, $strict)) {
						return true;
					}
				} else {
					if ($strict) {
						if (0 == strcmp($i, $needle)) {
							return true;
						}
					} else {
						if (0 == strcasecmp($i, $needle)) {
							return true;
						}
					}
				}
			}
			return false;
		}
	}
?>

Reply via email to