$s = "123456"; while (TRUE) { $result[] = $s; for($i = $len; $i >= 0; $i--) { break; } } if ($i < 0) break; for($j = $len; $s[$i] > $s[$j]; $j--); $t = $s[$j]; $s[$j] = $s[$i]; $s[$i] = $t; for($k = $i+1, $r = $len; $r > $k; $k++, $r--) { $t = $s[$r]; $s[$r] = $s[$k]; $s[$k] = $t; } }