zoombie
Member
- Dec 4, 2019
- 60
- 17
- 8
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/permutation-of-string-in-java
but it's not allow user input text,
please help me in php function
thank with best regard
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/permutation-of-string-in-java
but it's not allow user input text,
please help me in php function
thank with best regard
Code:
<!DOCTYPE html>
<html>
<body>
<?php
//Function for generating different permutations of the string
function generatePermutation($string,$start,$end){
if($start == $end-1){
echo "$string - ";
}
else{
for($i = $start; $i < $end; $i++){
//Swapping the string by fixing a character
$temp = $string[$start];
$string[$start] = $string[$i];
$string[$i] = $temp;
//Recursively calling function generatePermutation() for rest of the characters
generatePermutation($string,$start+1,$end);
//Backtracking and swapping the characters again.
$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>