PHP如何在2个数组的成员之间进行计算,并返回返回true的成员id


PHP How to compute between members of 2 arrays and return the id of the member that returns true?

我有一个函数和两个数组,这样:

    function subtract($x, $y){
     return $y-$x;
    }
    $a1=array(array("first", 5), array("second", 6), array("third", 4));
    $a2=array(3);
    $i=0;
    foreach ($a1 as $index=>$value){
    $result=array(subtract($value[$i], $a2[0]));
if($result=1){
//return third in this case}
    }

在foreach循环中,一旦函数返回true,我希望在这种情况下返回第三个。我该怎么做?

我试着使用相同的结构,但认为这不是最好的方法。

    function subtract($x, $y)
    {
        return $x-$y;
    }
$a1=array(array("first", 5), array("second", 6), array("third", 4));
$a2=array(3);
foreach ($a1 as $value)
    {
    $result=subtract($value[1], $a2[0]);
        if($result==1)
        {
            echo $value[0];
        }
    }