Jump to content

Archived

This topic is now archived and is closed to further replies.

flamerail

Can you assign while to a var?

Recommended Posts

Im trying to generate a table with while then assign it to a var for later use. Is it possible?

Also whats up with the phpfreaks chat? Its dead... is there an irc chat for us any where?

Share this post


Link to post
Share on other sites
I don't know why you'd really want to do that, however, any PHP can be assigned to a variable and executed at run time using eval().

[a href=\"http://us2.php.net/manual/en/function.eval.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.eval.php[/a]

I'll report the chat being down. Thanks.

Share this post


Link to post
Share on other sites
[!--quoteo(post=375613:date=May 20 2006, 09:01 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ May 20 2006, 09:01 PM) [snapback]375613[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I don't know why you'd really want to do that, however, any PHP can be assigned to a variable and executed at run time using eval().

[a href=\"http://us2.php.net/manual/en/function.eval.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.eval.php[/a]

I'll report the chat being down. Thanks.
[/quote]

That isnt doing quiet what I needed but thanks.

Share this post


Link to post
Share on other sites
well if you are looking to do like,

$blah = 'while';

$x = 0;
$blah ($x < 10) {
..
.
$x++;
}

the closest you are going to get is by using eval.

Share this post


Link to post
Share on other sites
Why don't you put the code to generate the table into a function. Then you can call the function when you are ready to use the code in it.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

Share this post


Link to post
Share on other sites
oh wait, i get it. so you want to do something like this:

[code]
$x = 0;

$blah = "<table>";
while ($x < 10) {
   $blah.= "<tr><td>" . $x . "</td></tr>";
   $x++;
}

$blah.="</table>";

echo $blah;
[/code]
$blah is a string that holds the entire table and contents.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.