Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Coping with the arrays having different numbers of members needs something like this (not tested):-</p> <pre><code>&lt;?php usort($DAs, "cmpDA"); usort($CAs, "cmpCA"); $DaAccount = 0; $CaAccount = 0; $DaKey = 0; $CaKey = 0; while($DaAccount &lt; 999999 OR $CaAccount &lt; 999999) { switch true { case $DAs[$DaKey]['DebitAccount'] == $CAs[$CaKey]['CreditAccount'] : echo "Account number is ".$DAs[$DaKey]['DebitAccount'].", Value is ".($CAs[$CaKey]['SUM(j.Amount)'] - $DAs[$DaKey]['SUM(j.Amount)'])." (".$CAs[$CaKey]['SUM(j.Amount)']." - ".$DAs[$DaKey]['SUM(j.Amount)'].")&lt;br /&gt;"; $DaKey = (($DaKey &lt; count($DAs)) ? $DaKey + 1 : 999999); $CaKey = (($CaKey &lt; count($DAs)) ? $CaKey + 1 : 999999); break; case $DAs[$DaKey]['DebitAccount'] &lt; $CAs[$CaKey]['CreditAccount'] : echo "Account number is ".$DAs[$DaKey]['DebitAccount'].", Value is ".(0 - $DAs[$DaKey]['SUM(j.Amount)'])." (0 - ".$DAs[$DaKey]['SUM(j.Amount)'].")&lt;br /&gt;"; $DaKey = (($DaKey &lt; count($DAs)) ? $DaKey + 1 : 999999); break; case $DAs[$DaKey]['DebitAccount'] &gt; $CAs[$CaKey]['CreditAccount'] : echo "Account number is ".$CAs[$CaKey]['CreditAccount'].", Value is ".($CAs[$CaKey]['SUM(j.Amount)'] - 0)." (".$CAs[$CaKey]['SUM(j.Amount)']." - 0)&lt;br /&gt;"; $CaKey = (($CaKey &lt; count($DAs)) ? $CaKey + 1 : 999999); break; } } function cmpDA($a, $b) { return (($a['DebitAccount'] == $b['DebitAccount']) ? 0 : (($a['DebitAccount'] &lt; $b['DebitAccount']) ? -1 : 1) ); } function cmpCA($a, $b) { return (($a['CreditAccount'] == $b['CreditAccount']) ? 0 : (($a['CreditAccount'] &lt; $b['CreditAccount']) ? -1 : 1) ); } ?&gt; </code></pre> <p>Sort the 2 arrays into the same key order. The do a while loop, while either array key isn't maxed out. When there keys match you can do the calculation. When one is bigger than the other then there is no matching record for the other so put it out an increment the array key to the other array. If it is the end of the array set the array key to something silly and large. Eventually both arrays will be completed and both keys set to something high.</p> <p>However if the data is stored on a database then it is likely to be FAR quicker and easier to do this in SQL.</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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