Skip to content

Instantly share code, notes, and snippets.

@floydian
Created August 11, 2010 00:28
Show Gist options
  • Save floydian/518282 to your computer and use it in GitHub Desktop.
Save floydian/518282 to your computer and use it in GitHub Desktop.
<?php
class Toggle {
private $config;
private $temp;
public function __construct() {
$args = func_get_args();
if (empty($args)) {
throw new Exception('Toggle requires an array or an argument list.');
} else if (is_array($args[0])) {
$config = $args[0];
} else {
$config = $args;
}
$this->config = $config;
}
public function get() {
if (empty($this->temp)) {
$this->temp = $this->config;
}
return array_shift($this->temp);
}
public function __toString() {
return $this->get();
}
}
<?php
$my_toggle = new Toggle('odd', 'even');
$my_table = "<table>\n";
for ($x = 1; $x <= 10; $x++) {
$row_class = $my_toggle->get();
$my_table .= <<<EOT
<tr class="$row_class">
<td>
a table cell...
</td>
</tr>\n
EOT;
}
$my_table = "</table>\n";
echo $my_table;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment