Announcement

Collapse
No announcement yet.

Is there a "set" implementation in PHP?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a "set" implementation in PHP?

    I've searched the online manual, but didn't find it. But I can't beleive there isn't any PHP implementation of sests?

    By set I mean somethign like this:

    if (myvar IN (green, yellow, blue)) { do_something; }

    or

    if (myvar IN (1, 2, 3)) { do_something; }

    The way I wrote it above generates a parse error.

    Is there a way to implement sets type in PHP?
    vB Drupal Community Plumbing | vB Survey | vBusy | vB Spell | vBouncer

  • #2
    dunno what you mean by sets, but if you want to check if a string is in an array you can do it by using the in_array function.

    example:
    PHP Code:
    <?php
    $var 
    "green";
    $array = array("green""yellow""blue");
    if(
    in_array($var$array)) {
    echo 
    "you see it's working!";
    }
    ?>
    here you can see it in action:
    http://www.saviourofstrength.de/test.php

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    X