Tuesday,
23rd February 2010
Article in Spanish

PHP switch with multiple values in case


This is an easy way to use a switch with multiple values, while its incorporation to the language is being discussed.

By index

<?php
    $c= array($name,$age);
    switch($c) {
        case ($c[0] != ''):
            exist();
        break;
        case ($c[1] < 1):
            sleep();
        break;
    }
?>

By key

<?php
    $c= array("name"=> $name,
              "age"=>$age);
    switch($c) {
        case ($c["name"] != ''):
            exist();
        break;
        case ($c["age"] < 1):
            sleep();
        break;
    }
?>
blog comments powered by Disqus
Bookmark and Share