Click to See Complete Forum and Search --> : for loop to re-create existing variable


kredd
09-06-2008, 10:03 PM
Hello all,
trying to use a for loop to loop thru some variables but i can't 'rebuild' the variable in the loop.



for($x=0; $x<$max; $x++){

if($varname_$x != ""){ //actual variable names are varname_0, varname_1, etc.

array_push($arr, $varname_$x);

}

}



any ideas? thanks!

scragar
09-06-2008, 10:09 PM
for($x=0; $x<$max; $x++){
$tmp = ${'varname_'.$x};
if($tmp != ""){
array_push($arr, $tmp);
}
}

kredd
09-06-2008, 10:23 PM
ah, thanks man. i *KNEW* it had something to do with the curly brackets! ha ;)