RE: [PHP] IF statement question...
| From: | Ford, Mike [LSS] | Date: | Wed, 19 May 2004 15:20:14 +0000 |
| Subject: | RE: [PHP] IF statement question... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-186542@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Tristan.Pretty@risk.sungard.com
> [mailto:Tristan.Pretty@risk.sungard.com]
> Sent: 19 May 2004 15:47
>
> If I'm being Dumb, I apologies...
> but When using this:
>
> $row[bands] = "1,2,3,4,5,6,7,8";
> $row2[id] = "7";
> if (strpos($row[bands], $row2[id]) != FALSE) {
> // do stuff
> }
>
> I get the No 13 (as it's inthe 13th place in the string) as my result.
>
> Now I'm aware that it should work, as it's not returning a
> false value... But I'm still not getting the correct output
> on my page...
(i) needs to be !== not != (since the substring might appear in position 0 and 0==FALSE).
(ii) post some lines of your actual code showing what you expect, and what you actually get.
(iii) to know exactly what we're dealing with, var_dump $row and $row2 before you do the
strpos, and cut'n'paste the results for us.
(iv) also, quote your string subscripts ($row['bands']) -- not vital, but suppresses a
constant-lookup and notice for each one, and hence is more efficient.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds
Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211