cooldude832 Posted July 26, 2007 Share Posted July 26, 2007 I'm trying to come up with a list of banned numbers so to say that looks like this below <?php $badnums = array(1,2,4,5,7,8,23); $num = $_SESSION['num']; if($num != $badnums){ //Good } else{ //bad } ?> I know you can't do that so what I thought of was something else like <?php $badnums = array(1,2,4,5,7,8,23); $num = $_SESSION['num']; $badnums = implode("&&".$num."!= ".,$badnums); if($num != $badnums){ //Good } else{ //bad } ?> Does that make sense? I think it would work but is there an easier way? Link to comment https://forums.phpfreaks.com/topic/61773-is-there-a-better-way/ Share on other sites More sharing options...
teng84 Posted July 26, 2007 Share Posted July 26, 2007 not clear? can you explain a bit and base on that code using in_array i guess is better Link to comment https://forums.phpfreaks.com/topic/61773-is-there-a-better-way/#findComment-307560 Share on other sites More sharing options...
cooldude832 Posted July 26, 2007 Author Share Posted July 26, 2007 that would about do it basically what i'm doing except i'm manually creating the additional comparison strings Link to comment https://forums.phpfreaks.com/topic/61773-is-there-a-better-way/#findComment-307563 Share on other sites More sharing options...
cooldude832 Posted July 26, 2007 Author Share Posted July 26, 2007 it be <?php $badnums = array(1,2,4,5,7,8,23); $num = $_SESSION['num']; $badnums = implode("&&".$num."!= ".,$badnums); if(!in_array($num,$badnums)){ //Good } else{ //bad } ?> Link to comment https://forums.phpfreaks.com/topic/61773-is-there-a-better-way/#findComment-307565 Share on other sites More sharing options...
Aureole Posted July 26, 2007 Share Posted July 26, 2007 <?php $banned= array(1, 3, 5, 7); $num = $_SESSION['num']; if (in_array($num, $banned)) { echo "You are Bant."; } else { ?> Your HTML here. <?php } ?> ?? Link to comment https://forums.phpfreaks.com/topic/61773-is-there-a-better-way/#findComment-307568 Share on other sites More sharing options...
teng84 Posted July 26, 2007 Share Posted July 26, 2007 ya thats better that using explode or looping to reach the condition you need Link to comment https://forums.phpfreaks.com/topic/61773-is-there-a-better-way/#findComment-307571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.