Created
August 11, 2010 00:28
-
-
Save floydian/518282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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