Note that there are some explanatory texts on larger screens.

plurals
  1. POProper Printing of Arrays in PHP
    primarykey
    data
    text
    <p>How can I print the array if it does not match the SiteID, just print the [Deposit] => 0, [Reload] => 0 and [Redemption] => 0.</p> <p>Here's my first function:</p> <pre><code> public function bindOwnerToSites(){ error_reporting (E_ALL^ E_NOTICE); foreach( $this-&gt;balance as $keysaa =&gt;$key_valuesa)//getsitebalance { foreach( $this-&gt;sites as $keys=&gt;$key_values)//getsites { if ($key_values['SiteID'] == $key_valuesa['SiteID']) { $this-&gt;arrays[$key_valuesa['SiteID']] = array('SiteID'=&gt;$key_valuesa['SiteID'],'Balance'=&gt;$key_valuesa['Balance'],'MinBalance'=&gt;$key_valuesa['MinBalance'],'MaxBalance'=&gt;$key_valuesa['MaxBalance'],'OwnerAID'=&gt;$key_values['OwnerAID'],'GroupID'=&gt;1); } } } print_r ($this-&gt;arrays,$return=null); } </code></pre> <p>And here's my second function:</p> <pre><code> public function computeGHComponents() { error_reporting (E_ALL^ E_NOTICE); $totals = NULL; foreach ($this-&gt;transaction as $t){ $amount = (float) $t['Amount']; if (isset($this-&gt;totals[ $t['SiteID'] ][ $t['TransactionType'] ])){ $this-&gt;totals[ $t['SiteID'] ][ $t['TransactionType'] ] += (float) $amount; } else { $this-&gt;totals[ $t['SiteID'] ][ $t['TransactionType'] ] = (float) $amount; } } foreach($this-&gt;totals as $keyb =&gt; $value) { //$this-&gt;result[$key] = array("Deposit"=&gt;$value['D'] , "Redemption"=&gt;$value['W'] , "Reload"=&gt;$value['R'] ); $this-&gt;result[$keyb]['Deposit'] = isset($value['D']) ? $value['D'] : 0; $this-&gt;result[$keyb]['Reload'] = isset($value['R']) ? $value['R'] : 0; $this-&gt;result[$keyb]['Redemption'] = isset($value['W']) ? $value['W'] : 0; } echo "&lt;pre&gt;"; print_r($this-&gt;result); } </code></pre> <p>Now I need to bind the result of two functions and I try this code:</p> <pre><code> public function bindGHComponentsToSites() { error_reporting (E_ALL^ E_NOTICE); foreach ($this-&gt;arrays as $keys =&gt; $data) { foreach($this-&gt;result as $keyss =&gt; $value){ if($data['SiteID'] == $keyss){ $merged = array_merge((array)$data, (array)$value); } else if ($data['SiteID'] != $keyss){ $val = array('Deposit'=&gt;0, 'Reload'=&gt;0, 'Redemption'=&gt;0); $merged = array_merge((array)$data, (array)$val); } } $this-&gt;combined[$data['SiteID']] = $merged; } print_r($this-&gt;combined); } </code></pre> <p>but the result of function shown like this:</p> <pre><code>Array ( [2] =&gt; Array ( [SiteID] =&gt; 2 [Balance] =&gt; 19000.00 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 1000000.00 [OwnerAID] =&gt; 83 [GroupID] =&gt; 1 [Deposit] =&gt; 1500 [Reload] =&gt; 1000 [Redemption] =&gt; 1000 ) [3] =&gt; Array ( [SiteID] =&gt; 3 [Balance] =&gt; 94000.99 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 500000.00 [OwnerAID] =&gt; 17 [GroupID] =&gt; 1 [Deposit] =&gt; 459000 [Reload] =&gt; 169100 [Redemption] =&gt; 703576 ) [4] =&gt; Array ( [SiteID] =&gt; 3 [Balance] =&gt; 94000.99 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 500000.00 [OwnerAID] =&gt; 17 [GroupID] =&gt; 1 [Deposit] =&gt; 459000 [Reload] =&gt; 169100 [Redemption] =&gt; 703576 ) ) </code></pre> <p>here's should be the right output:</p> <pre><code> Array ( [2] =&gt; Array ( [SiteID] =&gt; 2 [Balance] =&gt; 19000.00 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 1000000.00 [OwnerAID] =&gt; 83 [GroupID] =&gt; 1 [Deposit] =&gt; 1500 [Reload] =&gt; 1000 [Redemption] =&gt; 1000 ) [3] =&gt; Array ( [SiteID] =&gt; 3 [Balance] =&gt; 94000.99 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 500000.00 [OwnerAID] =&gt; 17 [GroupID] =&gt; 1 [Deposit] =&gt; 459000 [Reload] =&gt; 169100 [Redemption] =&gt; 703576 ) [4] =&gt; Array ( [SiteID] =&gt; 3 [Balance] =&gt; 94000.99 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 500000.00 [OwnerAID] =&gt; 17 [GroupID] =&gt; 1 [Deposit] =&gt; 0 [Reload] =&gt; 0 [Redemption] =&gt; 0 ) ) </code></pre> <p>but I got a wrong output. The Deposit, Reload and Redemption of Site ID => 4 should be equal to zero. How can I do that? Please guide me in proper way. Thank you in advance.</p>
    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.
 

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