1, 1 => 11, 2 => 12, 3 => 2, 4 => 21, 5 => 211, 6 => 212, 7 => 213, 8 => 214, 9 => 22, 10 => 23, 11 => 24, 12 => 3, 13 => 31, 14 => 32 ); for ($i = 0; $i < count($str); $i++) { if($str[$i] >= 0 && $str[$i] <= 10) { $a = $str[$i]; } if($str[$i] >= 10 && $str[$i] <= 100) { $b = $str[$i]; $table[$a][$b] = $b; } if($str[$i] >= 100 && $str[$i] <= 1000) { $c = $str[$i]; $table[$a][$b][$c] = $c; } } print "
"; print_r($table); ?>