Calculate the highest duplicate integers of two associative arrays

后端 未结 4 1741
清歌不尽
清歌不尽 2021-01-25 11:19

Given 2 associative arrays:

$fruits  = array ( \"d\" => \"lemon\", \"a\" => \"orange\", \"b\" => \"banana\", \"c\" => \"apple\" );
$fruits2 = array          


        
4条回答
  •  故里飘歌
    2021-01-25 12:21

    You don't need the ternary operator.
    Also, be careful with count() as it will fail if your array is null.
    They also need to be equal lengths or you'll get an error.

    if( is_array($value1)  && is_array($value2) && count($value1)==count($value2) ) {
        for ( $i = 0; $i < count($value1); $i++)
        {
            $test[] = ($value1[$i] == $value2[$i]);
        }
    }
    

提交回复
热议问题