ultrus Posted March 29, 2007 Share Posted March 29, 2007 Hello, I am trying to dynamically create new variables, and add values to those variables. In Flash, I would do so like this: for(i=0;i<10;i++) { var this["happy" + i]:String = "I am so happy."; } trace(happy1); //shows "I am so happy." in the output window. trace(happy5); //shows "I am so happy." in the output window. How would I do this in php? Thanks much for the help Quote Link to comment Share on other sites More sharing options...
fert Posted March 29, 2007 Share Posted March 29, 2007 for($i=0;$i<10;$i++) { $this["happy" + $i]= "I am so happy."; } echo $this['happy1']."<br>"; echo $this['happy5']."<br>"; Quote Link to comment Share on other sites More sharing options...
ultrus Posted March 29, 2007 Author Share Posted March 29, 2007 Cool! Looks simple enough to me. Thank you fert Quote Link to comment Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 for($i = 0;$i < 10;$i++) { $happy["$i"] = 'I am so Happy'; } echo $happy['1']; echo $happy['5']; Seems easier to me lol. Quote Link to comment Share on other sites More sharing options...
ultrus Posted March 29, 2007 Author Share Posted March 29, 2007 That works for what I need too. hehe. 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.