Skip to content

Instantly share code, notes, and snippets.

@E1101
Created May 25, 2015 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save E1101/03831ea7fb2570e06e66 to your computer and use it in GitHub Desktop.
Save E1101/03831ea7fb2570e06e66 to your computer and use it in GitHub Desktop.
array_intersect case-insensitive and ignoring tildes
<?php
function to_lower_and_without_tildes($str,$encoding="UTF-8") {
$str = preg_replace('/&([^;])[^;]*;/',"$1",htmlentities(mb_strtolower($str,$encoding),null,$encoding));
return $str;
}
function compare_function($a,$b) {
return to_lower_and_without_tildes($a)===to_lower_and_without_tildes($b)?0:1;
}
$array1 = array("a" => "gréen", "red", "blue");
$array2 = array("b" => "green", "yellow", "red");
$result = array_uintersect($array1, $array2,"compare_function");
print_r($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment