PHP比较两个字符串
示例我得到了一串数字
1 2 2 1 and another is 2 1 2 1
Run Code Online (Sandbox Code Playgroud)
结果将是真实的,因为它只是1 2 2 1和2 2 1 1的位置
但如果价值是
1 2 2 2 and another is 2 1 2 1
Run Code Online (Sandbox Code Playgroud)
结果将返回false,因为在第一个字符串中它出现了3次出现2,无论我们如何将1 2 2 2位置洗牌,它都不会给出2 1 2 1
另一个可能的例子是
1 2 3 1 and another is 1 2 3 3
Run Code Online (Sandbox Code Playgroud)
结果也是假的,因为无论我们如何洗牌1231都不会给我们1233
我怎么能做这个比较,是否有任何PHP函数可以比较一个shuffle字符串与非shuffle字符串
也许我可以使用str_shuffle并执行一个独特的数组推送,直到我得到这个字符串的24个组合.
$input_string = "1221";
$array_string = ();
while( count($array_string) != 24 )
{
$input_string = str_shuffle($input_string);
array_push($array_string, $input_string);
$array_string = array_unique($array_string);
}
//then lastly i …Run Code Online (Sandbox Code Playgroud) php ×1