[PHP] array_search() problem
Hi I'm runing a PHP Version 4.0.4pl1 on Solaris 8 X86 on apache, and I'm trying to search an array while(list($findId) = mysql_fetch_row($resultNextLast)){ $NextLast[] = $findId; } $currArrayPos = array_search($ImgId, $NextLast); and this code results this error: Fatal error: Call to undefined function: array_search() Any body have any idea what could be wrong? Thanks David
Re: [PHP] array_search() problem
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], [EMAIL PROTECTED] ? $sub = abcd; $subs[] = cde; $subs[] = iyu; $subs[] = abc; $subs[] = xyx; $match=false; 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
Re: [PHP] array_search() problem
What I was looking for was finding out what was the index of thet value, lets say I have a array with some values like (23, 56, 45, 47) and i don't know where the walue I'm looking for is indexed in the array and I want to find out what the indexnumber is, how would that be possable ? function array_index($array,$needle) { /* written by [EMAIL PROTECTED] */ foreach($array as $key=$value) if($value==$needle) return $key; return -1; } $array=array(23, 56, 45, 47); echo array_index($array,45); echo array_index($array,48); if(array_index($array,48)0)echo 'not found'; else echo 'found'; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php