[英]How to compare two array values in PHP
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: 现在,我需要比较两个SiteID以便进行绑定,这是我的功能:
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: 我曾经回显SiteID的比较,像这样:
echo($data['SiteID'] .'=='. $value['SiteID']); echo($ data ['SiteID']。'=='。$ value ['SiteID']);
but there's no value in $value['SiteID'] from the function of computeGHComponents(), it shows like this: 但是computeGHComponents()函数的$ value ['SiteID']中没有值,它显示如下:
2==
2==
2==
3==
3==
3==
how can I get the value of SiteID from computeGHComponents()? 如何从computeGHComponents()获取SiteID的值? 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: 我曾经使用print_r我的$ keyss,但发现它是SiteID,所以我像这样修改我的代码:
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...
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.