How to find all permutation of a String by allow user input text or number

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
zoombie
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Apr 07, 2021 1:19 am

Wed Apr 07, 2021 1:22 am

Hi all dear
can anyone help me how to find all permutation of a String by allow user input text or number and generate when user click on button,

user need to input text on number in input box and click generate button to show result of all permutation of a String
below is code i found from https://www.journaldev.com/526/permutat ... ng-in-java
but it's not allow user input text,

please help me in php function
thank with best regard

Code: Select all

<!DOCTYPE html>
<html>
<body>
<?php
function generatePermutation($string,$start,$end){ if($start == $end-1){ echo "$string - "; } else{ for($i = $start; $i < $end; $i++){ $temp = $string[$start]; $string[$start] = $string[$i]; $string[$i] = $temp; generatePermutation($string,$start+1,$end); $temp = $string[$start]; $string[$start] = $string[$i]; $string[$i] = $temp; } }
}
$str = "ABC";
$n = strlen($str);
echo "All the permutations of the string are: ";
generatePermutation($str,0,$n);
?>
</body>
</html>
Post Reply