Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function genDiff($data1, $data2) {
$result = [];
var_dump($data1);
if ($data1 && $data2) {
// Проверяем все ключи из первого массива
foreach ($data1 as $key => $value) {
if (array_key_exists($key, $data2)) {
if ($value == $data2[$key]) {
$result[$key] = 'unchanged';
} else {
$result[$key] = 'changed';
}
} else {
$result[$key] = 'deleted';
}
}
// Проверяем все ключи из второго массива
foreach ($data2 as $key => $value) {
if (!array_key_exists($key, $data1)) {
$result[$key] = 'added';
}
}
}
return $result;
}
$result4 = genDiff([], ['two' => 'own']);
var_dump($result3);