reub77 Posted May 1, 2006 Share Posted May 1, 2006 I'm having issues trying to retrieve variables in a For Loop. The page I'm trying to do this on is retrieving a number of variables defined by the user. If the user states they need to add 10 users to teh system then I need to retrieve 4 variables associated with each user. Each variable is named with a number at the end. eg. First Name would be $fname1Last Name would be $lname1Date of Employment would be $doe1Now, if 18 users are required I then allow the user to enter this info for all 18 users. The trouble I'm having is calling all this data to be inserted into a mail function. Here's my code:[code]for ($counter = 1; $counter <= $numcov; $counter++) { $a .= "User #".$counter.": $fname".$counter." $lname".$counter." Date of Employment: $doe".$counter."\n\n"; }[/code]I'm counting on being able to use the number in the variable name to call each of the user defined amount of variables. Is my code correct? Is there a better way to do this?Thanks[b]EDITED BY WILDTEEN88: PLEASE USE THE CODE TAGS WHEN SUBMITTING CODE. THE PHP TAGS NO LONGER EXIST[/b] Quote Link to comment Share on other sites More sharing options...
sasa Posted May 1, 2006 Share Posted May 1, 2006 ttry[code]$a .= "User #$counter: ${fname.$counter} ${lname.$counter} Date of Employment: ${doe.$counter}\n\n";[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.