[PHP] testing array_search

2004-06-11 Thread Bob Lockie
I'm having a very hard time testing array_search.
$j = array_search( $i, $errList );
echo j= . $j;
if (($j != false)  ($j = 0)) {
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] testing array_search

2004-06-11 Thread Daniel Clark
What output do you get?

 I'm having a very hard time testing array_search.

 $j = array_search( $i, $errList );
 echo j= . $j;
 if (($j != false)  ($j = 0)) {

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



Re: [PHP] testing array_search

2004-06-11 Thread Curt Zirzow
* Thus wrote Bob Lockie ([EMAIL PROTECTED]):
 I'm having a very hard time testing array_search.
 
 $j = array_search( $i, $errList );
 echo j= . $j;
 if (($j != false)  ($j = 0)) {

snip
mixed array_search ( mixed needle, array haystack [, bool strict])

Searches haystack for needle and returns the key if it is found in
the array, FALSE otherwise. 
/snip

When ever you see that a function that returns mixed with a possible
FALSE Boolean value. You must always test your result as follows:

if ($j !== FALSE) {
  // found an item
} else {
  // no item found
}


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

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



Re: [PHP] testing array_search

2004-06-11 Thread Bob Lockie
On 06/11/04 17:17 Curt Zirzow spoke:
* Thus wrote Bob Lockie ([EMAIL PROTECTED]):
I'm having a very hard time testing array_search.
$j = array_search( $i, $errList );
echo j= . $j;
if (($j != false)  ($j = 0)) {

snip
mixed array_search ( mixed needle, array haystack [, bool strict])
Searches haystack for needle and returns the key if it is found in
the array, FALSE otherwise. 
/snip

When ever you see that a function that returns mixed with a possible
FALSE Boolean value. You must always test your result as follows:
if ($j !== FALSE) {
  // found an item
} else {
  // no item found
}
Ok, I supected it was a boolean thing. :-(
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php