Page 1 of 1

Write to Dynamic arrays

Posted: Thu Jan 04, 2007 10:37 am
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?

Posted: Thu Jan 04, 2007 10:41 am
by onion2k

Code: Select all

${'arr'.$var}

Posted: Thu Jan 04, 2007 11:30 am
by volka
Adding another dimenson to the array might be easier.
$arr1 -> $arr[1]
$arr2 -> $arr[2]