You can even without sorting the array - turn its elements:
$str_1 = 'ΠΠΎΠΆΠΈ ΡΡΡΠΈΡΡΠΈΡΠ΅ΡΠΊΠΈΠ΅'; $str_2 = 'Π’ΡΡΠΈΡΡΠΈΡΠ΅ΡΠΊΠΈΠ΅ Π½ΠΎΠΆΠΈ'; var_dump( similar_str($str_1, $str_2) ); function similar_str(... $data) { [$a, $b] = array_map('mb_strtolower', $data); $b = join(' ', array_reverse(explode(' ', $b))); return $a == $b; }
UPD: As it turned out, the option with array_reverse () is only suitable for a couple of words, so I added a sort, as suggested in the comments:
$str_1 = 'ΠΠΎΠΆΠΈ ΠΊΠ°ΠΊΠΈΠ΅-ΡΠΎ ΡΡΡΠΈΡΡΠΈΡΠ΅ΡΠΊΠΈΠ΅'; $str_2 = 'Π’ΡΡΠΈΡΡΠΈΡΠ΅ΡΠΊΠΈΠ΅ Π½ΠΎΠΆΠΈ ΠΊΠ°ΠΊΠΈΠ΅-ΡΠΎ'; var_dump( similar_str($str_1, $str_2) ); function similar_str(... $data) { [$a, $b] = array_map(function($i){ $words = explode(' ', mb_strtolower($i)); sort($words); return $words; }, $data); return $a == $b; }
Π½ΠΎΠΆΠΈ ΡΡΡΠΈΡΡΠΈΡΠ΅ΡΠΊΠΈΠ΅
. That does not match withΠ½ΠΎΠΆΠΈ ΠΎΡ ΠΎΡΠ½ΠΈΡΡΠΈ
. - Akina