Home > other >  PHP how to compare two different elements of the multi-dimensional array of new value and old value?
PHP how to compare two different elements of the multi-dimensional array of new value and old value?

Time:11-22

$old_val=[
[' id '=& gt; 22,' num=& gt; 1),
[' id '=& gt; 24,' num=& gt; 2)
];
$new_val=[
[' id '=& gt; 22,' num=& gt; 1, 'kw=& gt; 40 s],
[' id '=& gt; 24,' num=& gt; 2, 'kw=& gt; 40],
[' id '=& gt; 26,' num=& gt; 1, 'kw=& gt; 40]
];

I want to compare two different elements of a multidimensional array, forming a new array, this format inserted into the database, how to do?
$new_arr=[
[' field_name=& gt; 'id', 'old_val=& gt; 22,' new_val=& gt; 22], [' field_name=& gt; 'num', 'old_val=& gt; 1,' new_val=& gt; 1], [' field_name=& gt; 'kw', 'old_val=& gt;' and 'new_val=& gt; 40 s],
[' field_name=& gt; 'id', 'old_val=& gt; 24,' new_val=& gt; 24], [' field_name=& gt; 'num', 'old_val=& gt; 2,' new_val=& gt; 2], [' field_name=& gt; 'kw', 'old_val=& gt;' and 'new_val=& gt; 40],
[' field_name=& gt; 'id', 'old_val=& gt; 26,' new_val=& gt; 26], [' field_name=& gt; 'num', 'old_val=& gt;' and 'new_val=& gt; 1], [' field_name=& gt;' kw ', 'old_val=& gt;' and 'new_val=& gt; 40]
];
  • Related