mkosmosports Posted October 30, 2006 Share Posted October 30, 2006 Hey.I want to set an if condition on a group of numbers...$group=$_GET["group"]; $num = array("1","2","3","4","5","6","7","8","9","10");if ($group != $num) //If the number represented by the group parameter is not among the numbers in the $num array{echo("sorry");}How come the above does not work for me?Upfront thanks to anyone who can help me out.. Link to comment https://forums.phpfreaks.com/topic/25548-setting-an-if-condition-on-arrays/ Share on other sites More sharing options...
kenrbnsn Posted October 30, 2006 Share Posted October 30, 2006 That doesn't work since you're comparing a value to an array. You want to use the function [url=http://www.php.net/in_array]in_array()[/url][code]<?php$group=$_GET["group"]; $num = array("1","2","3","4","5","6","7","8","9","10");if (!in_array($group,$num)) //If the number represented by the group parameter is not among the numbers in the $num array{ echo("sorry");}?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/25548-setting-an-if-condition-on-arrays/#findComment-116567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.