Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>please provide a working array fragment in future.</p> <pre><code>$transactions = array ( array( 'SiteID' =&gt; 147, 'Amount' =&gt; '500.00', 'TransactionType' =&gt; 'Deposit' ), array( 'SiteID' =&gt; 147, 'Amount' =&gt; '500.00', 'TransactionType' =&gt; 'Redemption'), array( 'SiteID' =&gt; 147, 'Amount' =&gt; '1500.00', 'TransactionType' =&gt; 'Deposit' ), array( 'SiteID' =&gt; 147, 'Amount' =&gt; '200.00', 'TransactionType' =&gt; 'Reload' ), array( 'SiteID' =&gt; 150, 'Amount' =&gt; '100.00', 'TransactionType' =&gt; 'Deposit' ), array( 'SiteID' =&gt; 3, 'Amount' =&gt; '500.00', 'TransactionType' =&gt; 'Redemption' ), array( 'SiteID' =&gt; 150, 'Amount' =&gt; '200.00', 'TransactionType' =&gt; 'Redemption' ), array( 'SiteID' =&gt; 3, 'Amount' =&gt; '500.00', 'TransactionType' =&gt; 'Deposit' ), array( 'SiteID' =&gt; 3, 'Amount' =&gt; '200.00', 'TransactionType' =&gt; 'Deposit' ), array( 'SiteID' =&gt; 3, 'Amount' =&gt; '200.00', 'TransactionType' =&gt; 'Reload' ), array( 'SiteID' =&gt;147, 'Amount' =&gt; '500.00', 'TransactionType' =&gt; 'Redemption' ) ); $totals = null; foreach ($transactions as $t){ $amount = (float) $t['Amount']; if (isset($totals[ $t['SiteID'] ][ $t['TransactionType'] ])){ $totals[ $t['SiteID'] ][ $t['TransactionType'] ] += (float) $amount; } else { $totals[ $t['SiteID'] ][ $t['TransactionType'] ] = (float) $amount; } } print_r ($totals); </code></pre> <p>This will produce a result like this:</p> <pre> Array ( [147] => Array ( [Deposit] => 2000 [Redemption] => 1000 [Reload] => 200 ) [150] => Array ( [Deposit] => 100 [Redemption] => 200 ) [3] => Array ( [Redemption] => 500 [Deposit] => 700 [Reload] => 200 ) ) </pre> <p>If you can deal with php notice warnings the loop can be shortened to:</p> <pre><code>foreach ($transactions as $t){ $totals[ $t['SiteID'] ][ $t['TransactionType'] ] += (float) $t['Amount']; } </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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