Jump to content

Archived

This topic is now archived and is closed to further replies.

mkosmosports

setting an if condition on arrays....

Recommended Posts

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..

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.