Jump to content

[SOLVED] hep with nested foreach


tomdchi

Recommended Posts

Hi, I am trying to create a csv that in turn is used in report generation.  I have the array below that I need to loop with two foreach loops.  Can someone please help with me to get the foreach's correct?

 

Thanks!

Tom

 

 

The array

 



Array ( [0] => Array ( [date] => 2009-11-08 [fundingid] => 123789456 [processed] => 1 [amount] => 341.00 
    [payments] => Array ( [0] => Array ( [id] => 29 [firstname] => Al [lastname] => Allen [userid] => 29 [amountin] => 110.00 [fundingdate] => 2009-11-09 [processed] => 1 [invoiceid] => 2 [fundingid] => 123789456 [pmttotal] => 341.00 ) 
                          [1] => Array ( [id] => 26 [firstname] => Robin [lastname] => Zander [userid] => 26 [amountin] => 110.00 [fundingdate] => 2009-11-09 [processed] => 1 [invoiceid] => 3 [fundingid] => 123789456 [pmttotal] => 341.00 ) 
                          [2] => Array ( [id] => 16 [firstname] => Tom [lastname] => vaughan [userid] => 16 [amountin] => 121.00 [fundingdate] => 2009-11-09 [processed] => 1 [invoiceid] => 1 [fundingid] => 123789456 [pmttotal] => 341.00 ) ) ) )

 

Code snippet that I am working on:

        foreach($deposits as $value=>$field)
        {
            $depdate = $field['date'];
            $transid = $field['fundingid'];
            $deptotal = $field['amount'];
            $depstatus = $field ['processed']; 
            
            foreach($key as $field2)
            {

                $name = $field2['firstname'].' '.$field2['lastname'];
                $fundingid = $field2['fundingid'];
                $fundingdate = $field2['fundingdate'];
                $processed = $field2['processed'];
                $amountin = $field2['amountin'];
                $invoiceid = $field2['invoiceid'];

                        fwrite($handle, ';');
                fwrite($handle, date('m-d-Y', strtotime($fundingdate)));
                fwrite($handle, ';');

                fwrite($handle, ';');
                fwrite($handle, $name);
                fwrite($handle, ';');	            

                fwrite($handle, ';');
                fwrite($handle, $invoiceid);
                fwrite($handle, ';');	

                fwrite($handle, ';');
                fwrite($handle, $fundingid);
                fwrite($handle, ';');
            
                fwrite($handle, ';');
                if ($processed == 1)
                {
            	    fwrite($handle, "Pending");
                }
                elseif ($processed == 2)
                {
                	fwrite($handle, "Processed");
                }	
                elseif ($processed == 3)
                {
                	fwrite($handle, "Refund Pending");
                }
                elseif ($processed == 4)
                {
                	fwrite($handle, "Refund Complete");
                }
    		    elseif ($processed == 5)
                {
                	fwrite($handle, "Trans Returned");
                }
       		    elseif ($processed == 6)
                {
                	fwrite($handle, "Processing");
                }	            
       		    elseif ($processed == 7)
                {
                	fwrite($handle, "Void");
                }
                fwrite($handle, ';');
         	    
         	fwrite($handle, ';');
                fwrite($handle, $amountin);
                fwrite($handle, ';');
    
                fwrite($handle, "\r\n");
            }
            fwrite($handle, "\r\n");
            fwrite($handle, "\r\n");
            fwrite($handle, "\r\n");
            fwrite($handle, "\r\n");
            
            fwrite($handle, ';;');
            fwrite($handle, $depdate);
            fwrite($handle, ';');
            
            fwrite($handle, ';');
            fwrite($handle, $transid);
            fwrite($handle, ';');
            
            fwrite($handle, ';');
            fwrite($handle, $deptotal);
            fwrite($handle, ';');
            
            fwrite($handle, ';');
            fwrite($handle, $depstatus);
        } 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.