我正在尝试在php中创建一个条件,如下所示 -
$variable = "132";
if($variable == "123"){
echo "Matched.";
}else{
echo "Not Matched.";
}
我想在这种情况下显示匹配,导致这两个值是相同的字符。
答案 0 :(得分:0)
非常感谢你,最后我得到了答案 -
$variable = "1432";
$var = str_split($variable);
sort($var);
if(implode("", $var) == "1234"){
echo "Matched.";
}else{
echo "Not Matched.";
}
答案 1 :(得分:0)
我会将字符串拆分为组成字符,并对它们执行array_diff。
$variable = str_split("132");
$variable_2 = str_split("123");
var_dump( array_diff($variable, $variable_2));
if(count(array_diff($variable, $variable_2)) == 0){
echo "Matched.";
}else{
echo "Not Matched.";
}