PHP array_intersect不区分大小写并忽略波浪号

是否有任何类似于“array_intersect”的函数,但它在模式不区分大小写并忽略波浪线?

array_intersect PHP函数将数组元素与===进行比较,因此我没有得到预期的结果.

例如,我想要这个代码

$array1 = array("a" => "gréen", "red", "blue");
$array2 = array("b" => "green", "yellow", "red");
$result = array_intersect($array1, $array2);
print_r($result);

输出gréen和红色.在认的array_intersect函数中,建议使用红色(正常原因===).

解决方案吗

先感谢您

解决方法:

<?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);

输出

Array
(
    [a] => gréen
    [0] => red
)

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...