> Hi I'm runing a PHP Version 4.0.4pl1 on Solaris 8 X86 on apache, and I'm
> trying to search an array

>From the manual: array_search (PHP 4 >= 4.0.5)

send earlier to this list:

Re: [PHP] Array - Match
From: Bas Jobsen <[EMAIL PROTECTED]>
To: "N. Pari Purna Chand" <[EMAIL PROTECTED]>, 

$sub = "abcd";

$subs[] = "cde";
$subs[] = "iyu";
$subs[] = "abc";
$subs[] = "xyx";
foreach($subs as $value)
 if($sub==$value){$match=true; break;}
if($match) echo 'found!';
else  echo 'not found!';

//or better use
//for PHP 4
if(in_array($sub,$subs))echo 'found!';
else  echo 'not found!';

//also possible
//for PHP 4 >= 4.0.5 && < 4.2.0
if(is_null(($b=array_search($sub,$subs))))  echo 'not found!';
else echo 'found! In $sub['.$b.']';
//or for  PHP 4 >= 4.2.0
if(($b=array_search($sub,$subs)))  echo 'found! In $sub['.$b.']';
else echo 'not found!';

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to