PHP first searches and compares two arrays, the same part and different parts to form a new array.

there is now an array of array An and another array of data. The first part of
is to find the corresponding array A from the array data.
requires the same four key-value pairs, that is, id,name,info1,info2.
then compare after finding, if ext1 is not empty An array. If empty, the data of the corresponding data array is used, and the value of the ext2 key of the data array is changed to 1, and everything else remains the same.
forms a new array newdata.

$arrA = [
    [
        "id" => "1",
        "name" => "3",
        "info1" => "1",
        "info2" => "a",
        "ext1" => "1",
        "ext2" => "a",
        "ext3" => "1",
    ],


 $arrData = array (  
    "0" => [
        "id" => "1",
        "name" => "3",
        "info1" => "1",
        "info2" => "a",
        "ext1" => "1",
        "ext2" => "a",
        "ext3" => "1",
    ],  
    "1" => [
        "id" => "2",
        "name" => "3",
        "info1" => "1",
        "info2" => "a",
        "ext1" => "1",
        "ext2" => "a",
        "ext3" => "1",
    ],
        ],  
    "2" => [
        "id" => "3",
        "name" => "2",
        "info1" => "1",
        "info2" => "a",
        "ext1" => "1",
        "ext2" => "a",
        "ext3" => "1",
    ],
); 
Php
Apr.10,2022

probably realize

<?php
$arrA = [
    [
        'id'    => '1',
        'name'  => '3',
        'info1' => '2',
        'info2' => 'a',
        'ext1'  => '1',
        'ext2'  => 'a',
        'ext3'  => '1',
    ],
    [
        'id'    => '1',
        'name'  => '3',
        'info1' => '1',
        'info2' => 'a',
        'ext1'  => '1',
        'ext2'  => 'a',
        'ext3'  => '1',
    ],
    [
        'id'    => '2',
        'name'  => '3',
        'info1' => '1',
        'info2' => 'a',
        'ext1'  => '',
        'ext2'  => 'a',
        'ext3'  => '1',
    ],
];
$arrData = [
    [
        'id'    => '1',
        'name'  => '3',
        'info1' => '1',
        'info2' => 'a',
        'ext1'  => '1',
        'ext2'  => 'a',
        'ext3'  => '1',
    ],
    [
        'id'    => '2',
        'name'  => '3',
        'info1' => '1',
        'info2' => 'a',
        'ext1'  => '1',
        'ext2'  => 'a',
        'ext3'  => '1',
    ],

    [
        'id'    => '3',
        'name'  => '2',
        'info1' => '1',
        'info2' => 'a',
        'ext1'  => '1',
        'ext2'  => 'a',
        'ext3'  => '1',
    ],
];
function diffTmp($arrA, $arrData)
{
    $result = [];
    $arrA = array_values($arrA);
    $arrData = array_values($arrData);
    $firstTmp = array_map('createTmp', $arrA);
    $lastTmp = array_map('createTmp', $arrData);
    foreach ($firstTmp as $fk => $ft) {
        foreach ($lastTmp as $lk => $lt) {
            if ($ft === $lt) {
                if (empty($arrA[$fk]['ext1'])) {
                    $arrData[$lk]['ext2'] = 1;
                    array_push($result, $arrData[$lk]);
                    continue;
                }
                array_push($result, $arrA[$fk]);
            }
        }
    }

    return $result;
}

function createTmp($array)
{
    $tmp = [
        'id'    => $array['id'],
        'name'  => $array['name'],
        'info1' => $array['info1'],
        'info2' => $array['info2'],
    ];
    ksort($tmp);
    return json_encode($tmp);
}

$result = diffTmp($arrA, $arrData);
var_dump($result);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3cf3f-2c34a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3cf3f-2c34a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?