Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind the result of two functions using array in PHP
    primarykey
    data
    text
    <p>I have two functions here:</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>the output of bindOwnerToSites() shown like this:</p> <pre><code>Array ( [1] =&gt; Array ( [SiteID] =&gt; 1 [Balance] =&gt; 2000 [MinBalance] =&gt; 1000 [MaxBalance] =&gt; 500 [OwnerAID] =&gt; 1 [GroupID] =&gt; 1 ) ) </code></pre> <p>Here's the code for the second function:</p> <pre><code> public function computeGHComponents() { error_reporting (E_ALL^ E_NOTICE); 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 $key =&gt; $value) { $this-&gt;result[$key] = array("Deposit"=&gt;$value['D'], "Redemption"=&gt;$value['W'], "Reload"=&gt;$value['R']); } print_r($this-&gt;result); } </code></pre> <p>And the output of computeGHComponents() shown like this:</p> <pre><code>Array ( [1] =&gt; Array ( [Deposit] =&gt; 10000 [Redemption] =&gt; 500.00 [Reload] =&gt; 200.00 ) ) </code></pre> <p>Now, I need to bind the result of the two functions, I'll try on my own but there something wrong with my codes, I need your help, I put everything here so I hope you better know what I suppose to achieved. Here's my code in binding :</p> <pre><code> public function bindGHComponentsToSites() { error_reporting (E_ALL^ E_NOTICE); $combined = array(); foreach($this-&gt;arrays as $key =&gt; $key_value){ foreach($this-&gt;result as $keys =&gt; $key_values){ $combined[$key_values['SiteID']] = array_merge((array)$key_value, (array)$key_values); } } print_r($combined); } </code></pre> <p>The result should be like this, How can I have this kind of result? I need your patience with this question, I'm just a beginner programmer, so hope you understand.</p> <pre><code>Array ( [1] =&gt; Array ( [SiteID] =&gt; 1 [Balance] =&gt; 2000 [MinBalance] =&gt; 1000 [MaxBalance] =&gt; 500 [OwnerAID] =&gt; 1 [GroupID] =&gt; 1 [Deposit] =&gt; 10000.00 [Redemption] =&gt; 500.00 [Reload] =&gt; 200.00 ) ) </code></pre> <p>Thanks in advance and Please guide me in proper way.</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