-
From: "andy" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 25, 2002 11:39 AM
Subject: Re: [PHP] how to make array_search start from 0?
> I can see what u are saying. Its all about the ===
>
> Anyhow.. this thing does not work in a loop. I guess
I can see what u are saying. Its all about the ===
Anyhow.. this thing does not work in a loop. I guess this is my prob. There
might be something wrong with the boolean. I tryed it with different
settings, but still wrong:
Here is what I mean:
$fruit = array('apple','banana','cranberry');
$
I can see what u are saying. Its all about the ===
Anyhow.. this thing does not work in a loop. I guess this is my prob. There
might be something wrong with the boolean. I tryed it with different
settings, but still wrong:
Here is what I mean:
$fruit = array('apple','banana','cranberry');
$
> -Original Message-
> From: andy [mailto:[EMAIL PROTECTED]]
> Sent: 25 April 2002 17:30
>
> I am passing an array through the URL with a ',' inbetween:
> var=php,mysql,super
> Parsing is done with: explode (',',$var). This gives me an
> array starting
> with 0
>
> Later on I have to se
g at index 1. Live and learn. :)
-Kevin
- Original Message -
From: "Ford, Mike [LSS]" <[EMAIL PROTECTED]>
To: "'Kevin Stone'" <[EMAIL PROTECTED]>; "PHP-general"
<[EMAIL PROTECTED]>
Sent: Thursday, April 25, 2002 11:12 AM
Subject: RE:
On Friday 26 April 2002 00:30, andy wrote:
> Hi there,
>
> I am passing an array through the URL with a ',' inbetween:
> var=php,mysql,super
> Parsing is done with: explode (',',$var). This gives me an array starting
> with 0
>
> Later on I have to search for lets say php with array_search.
>
> Un
> -Original Message-
> From: Kevin Stone [mailto:[EMAIL PROTECTED]]
> Sent: 25 April 2002 18:02
>
> Just looking at the manual here and it explains quite
> specifically that
> array_search() is meant to be used with associative arrays,
> not indexed
> arrays.
No it doesn't. How on ear
If the key is 0, array_search will return 0, it does not
start at 1.
$arr = array('apple','banana','cranberry');
$key = array_search('apple', $arr);
print $key; // 0
If 'apple' was not found, $key would then equal
to boolean false. Be sure to use "=== false"
to check failure because 0
Just looking at the manual here and it explains quite specifically that
array_search() is meant to be used with associative arrays, not indexed
arrays. I think the best way to do what you want is to do is to set up a
loop and test each index against eregi(); If true then you know your index.
-Ke
9 matches
Mail list logo