Jump to content

Make a dynamic variable


xionhack

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/211945-make-a-dynamic-variable/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.