在php Cakephp中计算一个数组的总数

i want add some statistic in my website, i want to show my revenues every month, when the car return from rent (the day : expected return month). I want to calculate the total of revenues (rental price) per month (Expected Return Date), someone can help me, how i can do that? enter image description here

and this is View/Location/admin_index.ctp :

  
<div class="row" >
<!--<meta http-equiv="refresh" content="5; URL=http://dhafer.com/admin/locations">-->
        
     <div class="col-lg-12">
                                                
        <h1 class="page-header" style="font-family: Kaushan Script';">Administrator<small> Locations management</small></h1>
            <ol class="breadcrumb">
               <li class="active">
                  <i class="fa fa-car"></i> Locations
               </li>
            </ol>
 
        <div class="panel panel-default">
                          
                         
                <div class="panel-heading" style="font-family: Kaushan Script';"><h3> Locations </h3></div>

                     <div class="table-responsive">

                        <table class="table table-bordered table-hover table-striped" style="font-family: 'Montserrat';">
                                <thead>
                                    <tr >
                                         



                                        <th class="actions"><?php echo __('Actions'); ?></th>
                                        <th><?php echo $this->Paginator->sort('id'); ?></th>
                                        <th><?php echo $this->Paginator->sort('status'); ?></th>
                                        <th><?php echo $this->Paginator->sort('departure_date'); ?></th>
                                        <th><?php echo $this->Paginator->sort('expected_return_date'); ?></th>
                                        <th><?php echo $this->Paginator->sort('user_id'); ?></th>
                                        <th><?php echo $this->Paginator->sort('agency_id'); ?></th>
                                        <th><?php echo $this->Paginator->sort('car_id'); ?></th>
                    <th class="actions"><?php echo __('Decision'); ?></th>
                    <th ><?php echo __('Days'); ?></th>
                    <th ><?php echo __('Rental price '); ?></th>
                                       
                                        
                                    </tr>
                                </thead>
                                <tbody>
                                
                                

                                    
                                    <?php foreach ($locations as $location): ?>
                                        <tr class="<?php   if($location['Location']['status']== '0'):echo "danger";else: echo "success";endif; ?>" style="color:black;">
                                    <td class="actions">
                    <?php echo $this->Html->link(' <i class="fa fa-eye" style="color:black;"></i>', array('action' => 'view', $location['Location']['id']),array('class'=>'btn-sm btn-sousse','escape' => false)); ?>
                                           

                                            <?php echo $this->Html->link('<i class="fa fa-pencil-square-o" style="color:white;"></i>', array('action' => 'edit', $location['Location']['id']),array('class'=>'btn-sm btn-primary','escape' => false)); ?>
                                            
           <?php echo $this->Html->link('<i class="fa fa-times-circle" style="color:white;"></i>', array('action' => 'delete', $location['Location']['id']),array('class'=>'btn-sm btn-slama','escape' => false), array(), __('Are you sure you want to delete # %s?', $location['Location']['id'])); ?>
                                        </td>
                                        <td style="font-family: 'Montserrat';"><?php echo $this->Html->link($location['User']['id'], array('controller' => 'users', 'action' => 'view', $location['User']['id'])); ?></td>
                                        <td style="font-family: 'Montserrat';">
<?php
                    if( $location['Location']['status'] != 0){ 
                    echo __('Accepted');}else{
                    echo __('Waiting response');
                    }
                     ?>
                                      </td>
                                        <td style="font-family: 'Montserrat';"><?php echo h($location['Location']['departure_date']); ?></td>
                                        
                                        <td style="font-family: 'Montserrat';"><?php echo h($location['Location']['expected_return_date']); ?></td>
                                        <td style="font-family: 'Montserrat';"><?php echo h($location['User']['first_name']); ?></td>
                                        
                                        <td style="font-family: 'Montserrat';"><?php echo $this->Html->link($location['Agency']['name'], array('controller' => 'agencies', 'action' => 'view', $location['Agency']['id'])); ?></td>
                                        
                                       
                                        
                                        <td style="font-family: 'Montserrat';"><?php echo $this->Html->link($location['Car']['title'], array('controller' => 'cars', 'action' => 'view', $location['Car']['id'])); ?></td>
                                       <td style="font-family: 'Montserrat';">
<?php
                    if( $location['Location']['status'] != 0){ 
                    echo $this->Html->link(    "Delete", array('action'=>'delete', $location['Location']['id']),array('class'=>'btn btn-danger'));}else{
                    echo $this->Html->link(    "Accept", array('action'=>'activate', $location['Location']['id']),array('class'=>'btn btn-success'));
                    }
                     ?>
                                      </td>
<td style="font-family: 'Montserrat';">
                                      <?php 


 

 $temp1=$location['Location']['expected_return_date'];
 $temp2 = $location['Location']['departure_date'];

$date1 = new DateTime($temp1);
$date2 = new DateTime($temp2);

$diff=$date1->diff($date2);
$days=$diff->format('%a days');
echo $days ;

 


   ?></td><td style="font-family: 'Montserrat';">
     
     <?php


            echo '$ '.$location['Car']['price'] * $days;


         ;?>
   </td>
                                        
                                    </tr>

                                 <?php endforeach; ?>
                                   
                               
                                </tbody>
                          </table>
                          <p>
                            <?php
                            echo $this->Paginator->counter(array(
                            'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
                            ));
                            ?>  </p>
                            <div class="paging">
                            <?php
                                echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
                                echo $this->Paginator->numbers(array('separator' => ''));
                                echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
                            ?>
                            </div>
                     </div>
                 </div>
                 <?php echo $this->Html->link(' <i class="fa fa-rss-square fa-1x" style="color:orange;"></i>', array('action' => 'admin_getlocations.xml'),array('class'=>'btn-lg btn-default','escape' => false)); ?>
              </div>















            </div>




 <script type="text/javascript">
 //setTimeout(function(){
   //window.location.reload(1);
//}, 10000);


 </script>

someone can help me?

</div>

I believe you should count statistics in the controller (unless you want it per page) by performing SUM() and COUNT() queries with Date/Time functions. There are a plenty of very powerful functions that can help you to calculate date intervals.

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html

(I assume that you use mysql or something similar.)

Please add some relevant DB-structure, so I could help you to build a query.