如何比较PHP 2数组值 [英] How to compare two array values in PHP

查看:158
本文介绍了如何比较PHP 2数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个功能,第一个是:

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);

} 

和所述第二函数是:

    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);  
    }

现在我需要在两个SITEID以绑定比较,这里是我的功能:

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']){
            }
     }
 }

我来回应SITEID的比较,像这样的:

I used to echo the comparing of SiteID, like this:

回声($数据['SITEID']'=='$值['SITEID']);

echo($data['SiteID'] .'=='. $value['SiteID']);

但有从computeGHComponents()的功能价值$ ['SITEID']没有价值,它表明这样的:

but there's no value in $value['SiteID'] from the function of computeGHComponents(), it shows like this:

 2==
 2==
 2==
 3==
 3==
 3==

我怎样才能SITEID从computeGHComponents()的值?请帮我修改我的codeS。谢谢你在前进。

how can I get the value of SiteID from computeGHComponents()? Please help me to modify my codes. Thank you in advance.

推荐答案

我以前的print_r我$ keyss,我发现它是如此的siteID修改我的code是这样的:

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...
            }
       }
    }

这篇关于如何比较PHP 2数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆