The best way to work with eval() is to start with what you want to declare:
eval( $ext_1 = '3^3^4^4'; ); //what i think you want but you can go from here
Now turn that into a string with variables available:
eval( '$ext_' . $y . ' = \'' . $pieces[$z] . '\';' );
and there you have it. From my experience with eval(), the ending semicolon is not needed for the expression to evaluate unless you have multiple commands or logical expressions. Also, be careful with your quotes.
I'm looking at your code and your coding is fairly well advanced, for example you're doing two things at once with count($pieces = explode('|',$extended)) - I'd never even thought of that! :-) it seems that you might however be better served using arrays in some fashion to parse the string.
Samuel
GiantComm wrote:Hi,
I am a little confused as how to do this with PHP.
I would like to create some variables on the fly within a While loop and have this so far.
<?php
$extended = "3^3^4^4^1|rrsrw|3|2|mth_scrn|1|3";
$extCount = count($pieces = explode("|", $extended));
$y = "1";
$z = "0";
$varName="ext_";
while($y <= $extCount){
// I need to create new variables call $ext_ with number appended to the end
$varName eval($y) = $pieces[$z]; // How do I create this variable on the fly?
$y++;
$z++;
}
?>
I used the EVAL for this purpose with Flash Actionscript (I think!) but cant figure out the correct syntax in PHP - and the documentation has confused me!!!
Any pointers would be much appreciated,
GiantComm...