kevin nally Posted January 24, 2010 Share Posted January 24, 2010 Hi folks and thanks for reading this. I am trying to solve a problem with an array of arrays; I have a function that calculates the number of combinations that can be created given an array of any length. the function works as print_r gives me the following output. Array ( [0] => Array ( [0] => 111 ) [1] => Array ( [0] => 201 ) ) Array ( [0] => Array ( [0] => 111 [1] => 201 ) ) ideally i would like each iteration of the loop below to create a new array so i need to use variable variables to create a new array based on $count in the for loop. $arrayOfBets = array(111, 201,301); for($count=1;$count<=count($arrayOfBets);$count++) { $newArray = comb($arrayOfBets, $count); // I would like to be able to create $newArraytwo $newArrayThree etc according to the $count variable. if not how do i separate the arrays in to separate arrays; print_r($newArray); } grateful for any help Link to comment https://forums.phpfreaks.com/topic/189621-variable-variables-and-or-array-of-arrays/ Share on other sites More sharing options...
wildteen88 Posted January 24, 2010 Share Posted January 24, 2010 Change $newArray = to $newArray[] = You will also want to add $newArray = array(); before the for loop Link to comment https://forums.phpfreaks.com/topic/189621-variable-variables-and-or-array-of-arrays/#findComment-1000795 Share on other sites More sharing options...
kevin nally Posted January 24, 2010 Author Share Posted January 24, 2010 sorry i cut the wrong code here is what i do have //process the number of combinations $arrayOfBets = array(111, 201,301); for($count=1;$count<=count($arrayOfBets);$count++) { $newArray=array(); while ($numberOfBets=combo($numberOfBets,$count)) { $newArray[]=// lost at this stage; } // I would like to be able to create $newArraytwo $newArrayThree etc according to the $count variable. if not how do i separate the arrays in to separate arrays; print_r($newArray); } Link to comment https://forums.phpfreaks.com/topic/189621-variable-variables-and-or-array-of-arrays/#findComment-1000801 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.