Last Updated: February 25, 2016
·
551
· morrelinko

Alternate Switch with PHP

<?php

function alternate_switch($condition, $cases)
{
    return $cases[$condition]();
}

$siteStatus = 'offline'; // Probably gotten from config or whatever!!

alternate_switch($siteStatus, [
    'offline' => function () {
            echo 'Site is offline';
        },
    'online' => function () {
            echo 'Site is online';
        }
]);