检查值50%或以上是否与多维数组(PHP)中的大海捞针匹配

检查值50%或以上是否与多维数组(PHP)中的大海捞针匹配,php,arrays,similarity,Php,Arrays,Similarity,我想检查多维数组中的值是否与我输入的“指针”相同50%或更多 我得到了一个函数,可以检查多维数组中的值是否相同: function in_array_r($needle, $haystack, $strict = true) { foreach ($haystack as $item) { if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array

我想检查多维数组中的值是否与我输入的“指针”相同50%或更多

我得到了一个函数,可以检查多维数组中的值是否相同:

function in_array_r($needle, $haystack, $strict = true) {
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
            return true;
        }
    }

    return false;
    }
但是如果给定的值百分比相同,我想返回函数true。 我想我需要集成一些东西,比如:
类似的文本($value1,$value2,$percent)


我尽可能避免使用递归函数

function in_array_r($needle, $haystack, $strict = true) {
    $eq = 0;
    $diff = 0;
    for($i=0,$n=count($haystack); $i<$n; $i++){
        for($j=0,$m=count($haystack[$i]); $j<$m; $j++){
            if (($strict && $haystack[$i][$j] === $needle) || $haystack[$i][$j] == $needle){
                $eq++;
            } else {
                $diff++;
            }
        }
    }
    return $eq/($eq+$diff);
}
数组中的函数($needle,$haystack,$strict=true){ $eq=0; $diff=0;
对于($i=0,$n=count($haystack);$i您想如何比较字符串?如果
$value1=“Apple”
$value2=“orange”
,您想如何说它们是相似的呢?比如
如果(“A”=“o”){//为每个字母做点什么}
function in_array_r($needle, $haystack, $strict = true) {
    $eq = 0;
    $diff = 0;
    for($i=0,$n=count($haystack); $i<$n; $i++){
        for($j=0,$m=count($haystack[$i]); $j<$m; $j++){
            if (($strict && $haystack[$i][$j] === $needle) || $haystack[$i][$j] == $needle){
                $eq++;
            } else {
                $diff++;
            }
        }
    }
    return $eq/($eq+$diff);
}