Write to Dynamic arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mevets
Forum Newbie
Posts: 23
Joined: Fri Sep 15, 2006 10:06 am

Write to Dynamic arrays

Post by mevets »

I need to be able to write to certain arrays depending on the number contained in var.

For instance, $num could contain the numbers 1 though 99. If the number is 1 then I want to write some data to $arr1, if it is 2 then I want to write to $arr2, and so on. Because the numbers can range from 1 to 99 I wish not to do a HUGE if else block (or even case).

Is there a way to dynamically decide which array to write to?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

${'arr'.$var}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Adding another dimenson to the array might be easier.
$arr1 -> $arr[1]
$arr2 -> $arr[2]
Post Reply