I'm trying to retrieve permutation set based on a string. However, i couldn't execute the function properly. I'm not really good with public static, or private or how should I call the function.
<?php namespace Helpers;
class Helper {
public static function permute($str,$i,$n)
{
if ($i == $n)
return "$str\n";
else {
for ($j = $i; $j < $n; $j++) {
swap($str,$i,$j);
permute($str, $i+1, $n);
swap($str,$i,$j); // backtrack.
}
}
}
public static function swap(&$str,$i,$j) {
$temp = $str[$i];
$str[$i] = $str[$j];
$str[$j] = $temp;
}}
This is how I call the function from my controller.
Helper::permute($str,0,strlen($str))
I'm getting this error:
Call to undefined function Helpers\swap()