Jump to content

setting an if condition on arrays....


mkosmosports

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..
Link to comment
https://forums.phpfreaks.com/topic/25548-setting-an-if-condition-on-arrays/
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

Archived

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

×
×
  • Create New...

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.