Re: Dynamic function calls within the echo function, possible?
| From: | Sean Malloy | Date: | Tue, 20 Jul 2004 02:08:13 +0000 |
| Subject: | Re: Dynamic function calls within the echo function, possible? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-191099@lists.php.net to get a copy of this message | ||
I know this isn't solving your problem, but here is how I do it:
class RowAlternator
{
private $on;
private $off;
private $state;
function RowAlternator($on = "On", $off = "Off")
{
$this->on = $on;
$this->off = $off;
}
function switchState()
{
$this->state = !$this->state;
}
function Next()
{
$this->switchState();
return $this->Current();
}
function Current()
{
if ($this->state)
return $this->on;
return $this->off;
}
}
then...
using CSS style attributes:
$row = new RowAlternator("background-color: #EDEDED;", "background-color:
#FFFFFF;");
$i = 10;
while ($i--)
{
echo "<tr style='" . $row->Next() .
"'><td>Hello</td></tr>";
}
or using CSS Class definitions
$row = new RowAlternator();
$i = 10;
while ($i--)
{
echo "<tr class='" . $row->Next() .
"'><td>Hello</td></tr>";
}
as far as dynamically calling functions in echo.. why not do this:
$row = 'row_color';
echo sprintf('%s<br />%s<br />%s', $row(), $row(), $row());
or something
btw, defining parameters like so: &o=null
only works in PHP 5.
"Jay Blanchard" <jay.blanchard@niicommunications.com> wrote in message
news:C8F323573C030A448F3E5A2B6FE2070B0430C677@nemesis...
[snip]
Well that could work, but i want to re call it every time it finds the
occurance of $row
if you said $row = row_color();
then echo "$row<br>$row<br>$row";
it would output the content of $row1 three times.
Because $row =row_color calls it, defines the returned value of row_color as
the contents of it, and never calls it again. I need it to dynamicly call it
every time around.
[/snip]
Top posting == bad
replying off list == bad
Then loop through the rows with either a for loop or while loop.
while(TRUE === $row){
echo row_color($row) . "<br>";
}