Page 1 of 1
Can variables contain flow control elements?
Posted: Thu Nov 18, 2004 8:10 am
by enfys
I need to execute some flow control but from within code that is embedded in quote marks e.g.
Code: Select all
<?php
$test = if($counter == 12) {
echo "Counter equals twelve";
}
$counter=12;
$test;
?>
Posted: Thu Nov 18, 2004 8:20 am
by kettle_drum
Code: Select all
$code = '$counter = 12;';
eval($code);
echo $counter;
etc. Just eval() the code.
Posted: Sun Nov 21, 2004 12:47 am
by jl
would this work?
Code: Select all
$func="if (\$counter==12) { echo 'foo' ; }" ;
$counter=12 ;
eval($func) ;
Posted: Sun Nov 21, 2004 12:55 am
by nigma
No. [php_man]exec()[/php_man] is used to execute an external program. Check out the
php manual entry on exec() for more information.
Posted: Sun Nov 21, 2004 1:18 am
by potsed
im not sure this is what your looking for
Code: Select all
function echoFoo($foo) {
echo $foo;
}
then call the function like
Code: Select all
$counter = 12;
$show = ($counter === 12) ? echoFoo($counter) : false;
Posted: Sun Nov 21, 2004 1:29 am
by jl
nigma wrote:No. [php_man]exec()[/php_man] is used to execute an external program. Check out the
php manual entry on exec() for more information.
Typo, clearly I meant eval()
Posted: Sun Nov 21, 2004 1:33 am
by nigma
jl wrote:nigma wrote:No. [php_man]exec()[/php_man] is used to execute an external program. Check out the
php manual entry on exec() for more information.
Typo, clearly I meant eval()
... Well how was I supposed to know
