Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The return for array_udiff function "data_compare_func" is some function that you define but it must return an integer less than, equal to, or greater than zero so its probably not the right function for your needs. A custom function like this should give you what you need:</p> <pre><code>// this function loops through both arrays to find a match in the other array // it will skip entry comparisons when it goes through $arr2 because you already did it the first time function find_diff($arr1, $arr2) { $ret = array(); // we need to do two loops to find missing entries from both arrays $ret = do_loop($arr1, $arr2, $ret, true); $ret = do_loop($arr2, $arr1, $ret, false); return $ret; } // this function does the looping though $arr1 to compare it to entries in $arr2 // you can skip entry comparison if $compare_entries is false function do_loop($arr1, $arr2, $ret, $compare_entries = true) { //look through all of $arr1 for same element in $arr2 based on $id for ($i=0;$i&lt;count($arr1);$i++) { $id = $arr1[$i]['id']; $found = false; for ($j=0;$j&lt;count($arr2);$j++) { // id match found if ($id == $arr2[$j]['id']) { $found = true; // only compare entries if you need to if ($compare_entries) { //check if other field is different if (strcmp($arr1[$i]['other'],$arr2[$j]['other']) != 0) { $ret = add_to_ret($arr1[$i], $ret); break; } //check if timestamp field is different if (strcmp($arr1[$i]['timestamp'],$arr2[$j]['timestamp']) != 0) { $ret = add_to_ret($arr1[$i], $ret); break; } } else { break; } } } // entry from $arr1[$i] was not found in $arr2 if (!$found) { $ret = add_to_ret($arr1[$i], $ret); } } return $ret; } //this function only adds the new entry to $ret if it's ID isn't already in $ret function add_to_ret($entry, $ret) { $id = $entry['id']; for ($i=0;$i&lt;count($ret);$i++) { if ($id == $ret[$i]['id']) { //skip adding, its already in there return $ret; } } //add it in $ret[] = $entry; return $ret; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload