Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://docs.php.net/array_udiff" rel="nofollow">http://docs.php.net/array_udiff</a>:<blockquote>The user supplied callback function is used for comparison. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. </blockquote>Your function always returns 1 if the elements are unequal which results in diffrent (wrong) comparisons decisions.</p> <pre><code>&lt;?php function epsilon_compare ($v1,$v2) { $epsilon = 0.02; $diff = $v1 - $v2; return abs($diff)&lt;=$epsilon ? 0 : $diff; } $db_values = array( "21" =&gt; 10.00, "22" =&gt; 20.00, "25" =&gt; 3.55); $post_values = array( "21" =&gt; 8.00, "22" =&gt; 20.01, "25" =&gt; 2.55 ); print_r(array_udiff($post_values, $db_values, "epsilon_compare")); </code></pre> <p>prints</p> <pre><code>Array ( [21] =&gt; 8 [25] =&gt; 2.55 ) </code></pre> <hr> <p>edit: using array_udiff_assoc</p> <pre><code>$db_values = array ( "1" =&gt; 7.55, "2" =&gt; 5.45, "3" =&gt; 5.45, "4" =&gt; 64.45, "5" =&gt; 54.75, "6" =&gt; 30.40, "7" =&gt; 56.99, "8" =&gt; 10.90, "9" =&gt; 60.85, "11" =&gt; 3.25, "12" =&gt; 13.05, "13" =&gt; 5.45, "14" =&gt; 8.00, "15" =&gt; 5.45, "16" =&gt; 13.05, "17" =&gt; 4.35 ); $post_values = array ( "1" =&gt; 7.55, "2" =&gt; 5.45, "3" =&gt; 5.45, "4" =&gt; 64.45, "5" =&gt; 54.75, "6" =&gt; 30.40, "7" =&gt; 56.99, "8" =&gt; 10.90, "9" =&gt; 60.85, "11" =&gt; 3.25, "12" =&gt; 13.05, "13" =&gt; 2.45, "14" =&gt; 8.00, "15" =&gt; 5.45, "16" =&gt; 12.05, "17" =&gt; 2.34 ); print_r(array_udiff_assoc($post_values, $db_values, "epsilon_compare")); </code></pre> <p>prints</p> <pre><code>Array ( [13] =&gt; 2.45 [16] =&gt; 12.05 [17] =&gt; 2.34 ) </code></pre>
    singulars
    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.
 

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