Skip to content

Instantly share code, notes, and snippets.

@adamkiss
Created December 5, 2012 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamkiss/4215822 to your computer and use it in GitHub Desktop.
Save adamkiss/4215822 to your computer and use it in GitHub Desktop.
EE's 'switch' – template function in pure PHP
<?php
$ee_switch_global = array();
function switch(){
global $ee_switch_global;
$args = func_get_args();
$key = array_shift($args);
if (array_key_exists($key,$ee_switch_global)){
$index = $ee_switch_global[$key]++;
if ($index === count($args))
$ee_switch_global[$key]=0;
$return $args[$index];
}else{
$ee_switch_global[$key]=1;
return $args[0];
}
}
?>
<div class="<?=switch('columns','left','center','right');?>">
<!-- content -->
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment