Re: Auto Incrementing a Variable name?
| From: | Leif K-Brooks | Date: | Tue, 25 Feb 2003 22:03:19 +0000 |
| Subject: | Re: Auto Incrementing a Variable name? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-137157@lists.php.net to get a copy of this message | ||
Should be:
${name$i}
Jeff Pauls wrote:
I get an error with this. PHP doesn't like "$name$i". for ($i = 1; $i <= 3; $i++) {-- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.$arr_name[$i] = $name$i; // I want $name1,$name2,$name3 etc....} I've looked at Variable variables but I don't think that is what I need. What about if I wanted something like $name_1_ff $name_2_ff $name_3_ff neither of these work. $name_$i_ff $name_.$i._ff Having something after causing more of a problem. First of all PHP can't find the value of "$name_" and "_ff" just breaks it more. Jeff ----- Original Message ----- From: "Rick Emery" <remery@emeryloftus.com> To: "Jeff Pauls" <jeff@taylorgeorge.com>; <php-general@lists.php.net> Sent: Tuesday, February 25, 2003 3:26 PM Subject: Re: [PHP] Auto Incrementing a Variable name?You're on the right track: for ($i = 1; $i <= 3; $i++) {variables:$arr_name[$i] = $name$i; // I want $name1,$name2,$name3 etc....} ----- Original Message ----- From: "Jeff Pauls" <jeff@taylorgeorge.com> To: <php-general@lists.php.net> Sent: Tuesday, February 25, 2003 3:18 PM Subject: [PHP] Auto Incrementing a Variable name? Hi, I've been playing with this for a while now. Say I had the following$name1 = "joe"; $name2 = "janis"; $name3 = "joanne"; Is there a way in php to increment the variable name not the value?Something like this....for ($i = 1; $i <= 3; $i++) {just loop through each$arr_name[$i] = $name.$i; // I want $name1,$name2,$name3 etc....} This way say if I had 500 database queries that need to be updated I couldand just change the record id..... for ($i = 1; $i <= 500; $i++) { $query_update = "UPDATE table SET name=' $arr_name[$i]', WHEREperson_id='$i";$result_update = mysql_query($query_update) or die("Query failed"); } instead of doing something like this: $query_update1 = "UPDATE table SET name=' $name1', WHERE person_id='1"; $result_update1 = mysql_query($query_update1) or die("Query failed"); $query_update2 = "UPDATE table SET name=' $name2', WHERE person_id='2"; $result_update2 = mysql_query($query_update2) or die("Query failed"); $query_update3 = "UPDATE table SET name=' $name3', WHERE person_id='3"; $result_update3 = mysql_query($query_update3) or die("Query failed"); etc..... Anybody? There has to be a way of doing this... Thanks, Jeff