Skip to content
Advertisement

Overwrite subarrays in one multidimensional array if different from another multidimensional array

I stuck on this and really don’t know how to solve it. I have two multi-dimensional arrays and need to match every “entry_id” from second array with first one. Then need to check if every “file_no” from second array is in database (first array) and “status” are matched with 1st array . If “status” is different, update second array with string (e.g. updated value) like this:

JavaScript

So I have first array from database:

JavaScript

And second array generated from script:

JavaScript

Thanks for every comment and sorry for english 🙂

Advertisement

Answer

This is by creating a temporary array to search in. This will use quite some memory when the arrays are big, but will result in faster execution time…

JavaScript

Output:

JavaScript

edit: This is possible too, whitout the temp array, but with a loop in a loop. This will be slower than the first one, but will consume less memory:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement