Avatar of Computer Guy
Computer Guy
 asked on

PHP Syntax Question

Hi,

How could I code this?

If the accounts are not equal to

<?php IF $_SESSION['_amember_user']['data']['account_name'] <> test, web, demo
echo "yes"
else echo ""
?>

Open in new window

PHPScripting Languages

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
petr_hlucin

Try this.
<?php
switch ($_SESSION['_amember_user']['data']['account_name']) {
case "test":
case "web":
case "demo":
    echo "yes";
    break;
default:
    echo "";
}
?>

Open in new window


Other possiblity would be to create an array containing test, web and demo and test whether the variable is part of this array.
petr_hlucin

Sorry, now I've noticed that I've put negation of your condition, the correct code is here:
<?php
switch ($_SESSION['_amember_user']['data']['account_name']) {
case "test":
case "web":
case "demo":
    echo "";
    break;
default:
    echo "yes";
}
?>

Open in new window

ravenpl

probably little easier to write

if (in_array($_SESSION['_amember_user']['data']['account_name'], array('test', 'web', 'demo'))
{...

Refer http://www.php.net/manual/en/function.in-array.php
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ray Paseur

Thanks for the points - it's a really good question, ~Ray