andy3367 Posted December 29, 2008 Share Posted December 29, 2008 I'm quite new to PHP, and am trying to follow a book example of something. The sample code in the book includes the following snippet: $names = array ("Lee Marvin","Joe Smith","John Doe"); if (!in_array (strtolower ($_GET['sstring']), strtolower($names))){ //Then return with an error. ?><span style="color: #FF0000;">Name not found...</span><?php } else { //At this point we would go to the processing script. ?><span style="color: #FF0000;">Form would now submit...</span><?php } This code returns the error, "Warning: in_array() [function.in-array]: Wrong datatype for second argument," in reference to the in_array statement. If I remove the second strtolower function, all works well. So my question is, how do I do the case conversion on the array to ensure proper matching? The idea of the code is to allow LEE MARVIN, lEE marVin, etc., to match with Lee Marvin. Help and thanks. Link to comment https://forums.phpfreaks.com/topic/138771-using-strtolower-inside-in_array/ Share on other sites More sharing options...
DarkWater Posted December 29, 2008 Share Posted December 29, 2008 if (!in_array(strtolower($_GET['sstring']), array_map('strtolower', $names))) { That SHOULD work. And should the GET variable be 'sstring', or did you mean 'string'? Link to comment https://forums.phpfreaks.com/topic/138771-using-strtolower-inside-in_array/#findComment-725595 Share on other sites More sharing options...
andy3367 Posted December 31, 2008 Author Share Posted December 31, 2008 I thought it should work, too, but it doesn't. Very odd. And yeah, the example does pass "sstring" as the parameter. Oh well, I'll just delete the offending function and move on. FYI, the website hosting my programs uses "PHP 5.2.*" so I don't know what's up. Maybe I'll email them... Thanks for the reply. Link to comment https://forums.phpfreaks.com/topic/138771-using-strtolower-inside-in_array/#findComment-727075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.