i have two functions, the first one is:
public function computeGHComponents()
{
error_reporting (E_ALL^ E_NOTICE);
$totals = NULL;
foreach ($this->transaction 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;
}
}
foreach($totals as $key => $value)
{
$this->result[$key]['Deposit'] = isset($value['D']) ? $value['D'] : 0;
$this->result[$key]['Reload'] = isset($value['R']) ? $value['R'] : 0;
$this->result[$key]['Redemption'] = isset($value['W']) ? $value['W'] : 0;
}
echo "<pre>";
print_r($this->result);
}
and the second function is:
public function bindOwnerToSites(){
error_reporting (E_ALL^ E_NOTICE);
foreach( $this->balance as $keysaa =>$key_valuesa)//getsitebalance
{
foreach( $this->sites as $keys=>$key_values)//getsites
{
if ($key_values['SiteID'] == $key_valuesa['SiteID'])
{
$this->arrays[$key_valuesa['SiteID']] = array('SiteID'=>$key_valuesa['SiteID'],'Balance'=>$key_valuesa['Balance'],'MinBalance'=>$key_valuesa['MinBalance'],'MaxBalance'=>$key_valuesa['MaxBalance'],'OwnerAID'=>$key_values['OwnerAID'],'GroupID'=>1);
}
}
}
print_r ($this->arrays,$return=null);
}
Now I need to compare both SiteID in order to bind and here's my function:
public function bindGHComponentsToSites()
{
error_reporting (E_ALL^ E_NOTICE);
foreach ($this->arrays as $keys => $data) {
foreach($this->result as $key => $value){
if ($data['SiteID'] == $value['SiteID']){
}
}
}
I used to echo the comparing of SiteID, like this:
echo($data['SiteID'] .'=='. $value['SiteID']);
but there's no value in $value['SiteID'] from the function of computeGHComponents(), it shows like this:
2==
2==
2==
3==
3==
3==
how can I get the value of SiteID from computeGHComponents()? Please help me to modify my codes. Thank you in advance.
I used to print_r my $keyss and I found out that it was the SiteID so I modify my code like this:
public function bindGHComponentsToSites()
{
error_reporting (E_ALL^ E_NOTICE);
foreach ($this->arrays as $keys => $data) {
foreach($this->result as $keyss => $value){
//print_r($keyss );echo '<br/>';
if($data['SiteID'] == $keyss){
//statement...
}
}
}
来源:https://stackoverflow.com/questions/11980402/how-to-compare-two-array-values-in-php