Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting of Array
    text
    copied!<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>Here's the code but it print's like this:</p> <pre><code>Array ( [147] =&gt; Array ( [D] =&gt; 455500 [W] =&gt; 460216.4 [R] =&gt; 158000 ) [145] =&gt; Array ( [D] =&gt; 85500 [W] =&gt; 78763.75 [R] =&gt; 14500 ) [146] =&gt; Array ( [D] =&gt; 64200 [W] =&gt; 91121.94 [R] =&gt; 42800 ) </code></pre> <p>I need to print_r the result like this:</p> <pre><code>Array ( [147] =&gt; Array ( [Deposit] =&gt; 455500 [Redemption] =&gt; 460216.4 [Reload] =&gt; 158000 ) [145] =&gt; Array ( [Deposit] =&gt; 85500 [Redemption] =&gt; 78763.75 [Reload] =&gt; 14500 ) [146] =&gt; Array ( [Deposit] =&gt; 64200 [Redemption] =&gt; 91121.94 [Reload] =&gt; 42800 ) </code></pre> <p><strong>R - Reload, W - Redemption and D - Deposit.</strong></p> <p>Thanks and Please Response.</p>
 

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