如何将两个具有相同数组键的数组组合起来,如果值相同则不显示,如果不同则显示

how to combine two arrays with the same array key then if the value is the same then it is not displayed and if it is different it will be displayed

我整天都在为此苦苦挣扎,希望有另一双眼睛能给我一些见识。我不确定我什至以正确的方式接近这个。我有两个数组,但这些数组有不同的数字列表。我正在使用 Laravel.

构建应用
$naflr = array(
    0 => "NA"
    1 => "A2"
    2 => "A2"
    3 => "A1"
    4 => "A1"
    5 => "A1"
    ...
    49 =>"A3"
)

$fuzifikasi = array(
    0 => "A2"
    1 => "A1"
    2 => "A4"
    3 => "A1"
    4 => "A1"
    5 => "A1"
    ...
    48 => "A4"
)

如何使用 FUZIFIKASI 从 NAFLR 数组中过滤值数组,我希望结果是这样的

$resul = array(
    [na] = array(
        0 => "A2"
    )

    [A2] = array(
        0 = > "A1"
        1 => "A4"
    )
    ....
)

如果我的描述正确,那么你需要做的就是遍历你的第一个数组,检查你的第二个数组中是否存在具有相同索引的项目(从你的解释中不清楚,那些是否总是有项目数是否完全相同),如果是,则使用第一个数组中的值作为键将其添加到结果数组中:

$result = [];

foreach($naflr as $index => $value) {
    if(isset($fuzifikasi[$index])) {
        $result[$value][] = $fuzifikasi[$index];
    }
}

var_dump($result);

https://3v4l.org/L34El