xionhack Posted August 28, 2010 Share Posted August 28, 2010 Hello. I want to create some variables dynamically. I have this so far: for($i = 1; $i <= 4 ; $i++){ $a = 'member' . $i; $$a = array(); } Does that give me this 4 arrays?: $member1, $member2, $member3 and $member4? Of course I want some process inside of the loop, but that would depend on the variables. Would that work? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/211945-make-a-dynamic-variable/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 28, 2010 Share Posted August 28, 2010 Just use an array in the first place. Why you might ask? Because you can then reference the data using array functions and you don't need to keep track of how many sequentially named variables you created or what their names were. Also, using variable variables is three times slower than using array variables. Quote Link to comment https://forums.phpfreaks.com/topic/211945-make-a-dynamic-variable/#findComment-1104585 Share on other sites More sharing options...
xionhack Posted August 28, 2010 Author Share Posted August 28, 2010 Thank you, that makes sense! Quote Link to comment https://forums.phpfreaks.com/topic/211945-make-a-dynamic-variable/#findComment-1104588 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.