-1

I am trying to create a condition in php like given below-

$variable = "132";
if($variable == "123"){
    echo "Matched.";
}else{
    echo "Not Matched.";
}

I want to show Matched in this condition, cause these two values are same character.

Mysterious
  • 51
  • 7
  • i dont understand –  Oct 23 '16 at 09:53
  • Basically the condition is false, but i need to make it true, See the characters between them, these are same but in different order. – Mysterious Oct 23 '16 at 09:55
  • Check this: [http://stackoverflow.com/questions/25589215/php-compare-two-string-in-random-position](http://stackoverflow.com/questions/25589215/php-compare-two-string-in-random-position) – Murad Hasan Oct 23 '16 at 10:15

2 Answers2

0

Thank you so much, finally i got my answer-

$variable = "1432";
$var = str_split($variable);
sort($var);
if(implode("", $var) == "1234"){
    echo "Matched.";
}else{
    echo "Not Matched.";
}
Mysterious
  • 51
  • 7
0

I would split the strings into the constituent characters and do array_diff on them.

$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.";
}
namingFailed
  • 289
  • 4
  • 10