Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php function genDiff($data1, $data2) { $result = []; var_dump($data2); 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);
Copy Clear