1

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.

4
  • variable scope issue by the looks of it. php.net/manual/en/language.variables.scope.php Commented Aug 16, 2012 at 3:46
  • @ Dagon, how can I modify my codes using of that? Thank you so much. Commented Aug 16, 2012 at 3:48
  • You'll have to use print_r or var_dump to show us the content to both arrays, otherwise there's no way we can guess the structure... Commented Aug 16, 2012 at 4:32
  • I already used the print_r and echo to test my arrays, but I can get the value of SiteID of ComputeGHComponents(). Please help me. Commented Aug 16, 2012 at 5:39

1 Answer 1

1

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...
            }
       }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.