tags:

views:

178

answers:

1

This is a php question.

I have an array of arrays:

Array ( [1] => Array ( [1] => 1 [2] => 2 [3] => 3) [2] => Array ( [4] => 4 ) [3] => Array ( [7] => 7 [8] => 8 [9] => 9 ) [4] => Array ( [36] => 36 ) )

I need to make all possible combinations in order but never out of order, and never missing a previous possible..that likely a bad explanation but this is what i mean:

1

1 - 4

1 - 4 - 7

1 - 4 - 8

1 - 4 - 9

1 - 4 - 7 - 36

1 - 4 - 8 - 36

1 - 4 - 9 - 36

I do not ever want to get 1 - 9 - 4 as in it must use the arrays as the order, and I cannot skip any like so 1 - 9 - 36

Any help would be seriously appreciated!

I tried the solution below (on a larger more realistic array):

$myarray = 'a:4:{i:1;a:29:{i:1;s:1:"1";i:2;s:1:"2";i:3;s:1:"3";i:10;s:2:"10";i:11;s:2:"11";i:12;s:2:"12";i:13;s:2:"13";i:14;s:2:"14";i:15;s:2:"15";i:16;s:2:"16";i:17;s:2:"17";i:18;s:2:"18";i:19;s:2:"19";i:20;s:2:"20";i:21;s:2:"21";i:22;s:2:"22";i:23;s:2:"23";i:24;s:2:"24";i:25;s:2:"25";i:26;s:2:"26";i:27;s:2:"27";i:28;s:2:"28";i:29;s:2:"29";i:30;s:2:"30";i:31;s:2:"31";i:32;s:2:"32";i:33;s:2:"33";i:34;s:2:"34";i:35;s:2:"35";}i:2;a:3:{i:4;s:1:"4";i:5;s:1:"5";i:6;s:1:"6";}i:3;a:3:{i:7;s:1:"7";i:8;s:1:"8";i:9;s:1:"9";}i:4;a:2:{i:36;s:2:"36";i:37;s:2:"37";}}';

$yourarray = unserialize($myarray);

$array_iter = new RecursiveArrayIterator($yourarray); $iter_iter = new RecursiveIteratorIterator($array_iter);

foreach($iter_iter as $iwishitwashomework) { echo $iwishitwashomework; }`

this is what it printed:

12310111213141516171819202122232425262728293031323334354567893637

+4  A: 
$array_iter   = new RecursiveArrayIterator($yourarray);
$iter_iter    = new RecursiveIteratorIterator($array_iter);

foreach($iter_iter as $myhomework)
{
echo $myhomework;
}
streetparade
as $myhomework... that was the greatest part. lol! +1
Dustin Hansen
this is what it printed:12310111213141516171819202122232425262728293031323334354567893637
jpstrikesback