calmchess Posted November 9, 2012 Share Posted November 9, 2012 if I have var0 var1 var2 how do i loop through those variable names with a for loop? example var+i Link to comment https://forums.phpfreaks.com/topic/270506-how-do-i-increment-a-variable-name-loop/ Share on other sites More sharing options...
requinix Posted November 9, 2012 Share Posted November 9, 2012 Use an array instead. Link to comment https://forums.phpfreaks.com/topic/270506-how-do-i-increment-a-variable-name-loop/#findComment-1391343 Share on other sites More sharing options...
Maq Posted November 9, 2012 Share Posted November 9, 2012 To expand on what requinix suggested, your design seems to be flawed if you need to do something like that. Show us some code and explain what you are trying to do. Link to comment https://forums.phpfreaks.com/topic/270506-how-do-i-increment-a-variable-name-loop/#findComment-1391344 Share on other sites More sharing options...
codefossa Posted November 9, 2012 Share Posted November 9, 2012 Here's two options. You could do it a couple other ways too but I don't really know what you're doing since you didn't show code. // Wait to Load Page window.addEventListener("load", function() { // Function function myFunc1() { alert("Function 1"); } // Function function myFunc2() { alert("Function 2"); } // Loop Numbers for (var i = 1; i < 3; i++) { // Evaluate / Execute String eval("myFunc" + i + "();"); } }, false); // Wait to Load Page window.addEventListener("load", function() { // Function function myFunc1() { alert("Function 1"); } // Function function myFunc2() { alert("Function 2"); } var myFuncs = [ myFunc1, myFunc2 ]; // Loop Functions for (var i in myFuncs) { // Execute Function myFuncs[i](); } }, false); Link to comment https://forums.phpfreaks.com/topic/270506-how-do-i-increment-a-variable-name-loop/#findComment-1391392 Share on other sites More sharing options...
calmchess Posted November 26, 2012 Author Share Posted November 26, 2012 well I do as I've asked allot in actionscript I suppose I can just push each variables data into an array and then iteriate over the array. I just didn't want to make the extra step. If what I ask were possible then you would have answered diffrently since it would be very basic. I don't have any code to show I'm just asking basic questions. Thanks for your time. Javascript is very verbose anyway so I guess making some extra steps will be well worth the effort. --calmchess Link to comment https://forums.phpfreaks.com/topic/270506-how-do-i-increment-a-variable-name-loop/#findComment-1395227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.