Michdd Posted November 8, 2008 Share Posted November 8, 2008 If I use an array to store different names, then I use an if statement to see if the name is something other than in the array, would I do it like this: $input = $_POST['input']; $name[1] = "somename"; $name[2] = "somename2"; if($input != $name){ } Would that work? Link to comment https://forums.phpfreaks.com/topic/131962-array-help/ Share on other sites More sharing options...
runnerjp Posted November 8, 2008 Share Posted November 8, 2008 <?php if(in_array($name[] != $input)) { echo 'foo'; } ?> i think this is it as you would have to check whats in the array would u not Link to comment https://forums.phpfreaks.com/topic/131962-array-help/#findComment-685670 Share on other sites More sharing options...
Barand Posted November 8, 2008 Share Posted November 8, 2008 No, you need to check if the name is contained within the array. The correct syntax is if (in_array($input, $name)) Link to comment https://forums.phpfreaks.com/topic/131962-array-help/#findComment-685672 Share on other sites More sharing options...
Barand Posted November 8, 2008 Share Posted November 8, 2008 @runnerjp http://uk3.php.net/manual/en/function.in-array.php Link to comment https://forums.phpfreaks.com/topic/131962-array-help/#findComment-685676 Share on other sites More sharing options...
runnerjp Posted November 8, 2008 Share Posted November 8, 2008 ahh sorry yes my mistake should be something like <?php $name = array('name1','name2','name3'); if(in_array($_POST['input'],$name)) { echo 'foo'; } ?> just seen your post barand... cheers i was getting mixed up with stuff lol Link to comment https://forums.phpfreaks.com/topic/131962-array-help/#findComment-685678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.