Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
i have an array in php like this:
Array ( [0] => Array ( [post_date] => 2017-07-22 [num] => 1 )
[1] => Array ( [post_date] => 2017-07-24 [num] => 2 )
[2] => Array ( [post_date] => 2017-07-26 [num] => 5 ))
i want to change it to this array:
Array ( [0] => Array ( [post_date] => 2017-07-22 [num] => 1 )
[1] => Array ( [post_date] => 2017-07-23 [num] => 0 )
[2] => Array ( [post_date] => 2017-07-24 [num] => 2 )
[3] => Array ( [post_date] => 2017-07-25 [num] => 0 )
[4] => Array ( [post_date] => 2017-07-26 [num] => 5 ))
how to do this?
Try this code and hope it's clear enough, the idea behind this solution is very simple:
First we sort our array using a user-defined comparison function by the post_date column value, this will helps us later when looping over the dates.
After that we make sure that the array contains at least two value to compare by starting the for loop from 1 and make sure the size of the array is greater than 1.If not we return the array as it is.
$i = 1; $i < count($array); => count($array) > 1 => at least 2
values.
Next we calculate the difference between two consecutive post_date of the array, if the difference is 1 day so we have two consecutive days, else we have to add the next day to the array from the "$i" position of post_date by using this helpers function:
array_splice($array, $i, 0, [[
'post_date' => $date1->modify('+1 day')->format('Y-m-d'),
'num' => 0,
]]);
Which will add 1 day the post_date and push other values to the right of the array which make the size of the array bigger ( +1 value) and will add another iteration for the for loop.
At the end of the loop, we will get a full array of consecutives days as the OP want.
<?php
$array = [
['post_date' => '2017-07-22','num' => '1'],
['post_date' => '2017-07-26','num' => '5'],
['post_date' => '2017-07-24','num' => '2'],
];
sort($array);
$count = count($array);
for($i = 1; $i < $count; $i++) {
$date1 = new DateTime($array[$i-1]['post_date']);
$date2 = new DateTime($array[$i]['post_date']);
$diff = $date2->diff($date1)->format("%a");
if(1 < $diff) {
array_splice($array, $i, 0, [[
'post_date' => $date1->modify('+1 day')->format('Y-m-d'),
'num' => 0,
]]);
$count++;
}
}
echo "<pre>";
print_r($array);
the output :
Array
(
[0] => Array
(
[post_date] => 2017-07-22
[num] => 1
)
[1] => Array
(
[post_date] => 2017-07-23
[num] => 0
)
[2] => Array
(
[post_date] => 2017-07-24
[num] => 2
)
[3] => Array
(
[post_date] => 2017-07-25
[num] => 0
)
[4] => Array
(
[post_date] => 2017-07-26
[num] => 5
)
)
Hope my post will be helpful, Here we are using PHP Datetime
Try this code snippet here
<?php
ini_set('display_errors', 1);
$array=
array (
0 =>
array (
'post_date' => '2017-07-22',
'num' => '1',
),
1 =>
array (
'post_date' => '2017-07-24',
'num' => '2',
),
2 =>
array (
'post_date' => '2017-07-26',
'num' => '5',
),
);
$dates= array_column($array, 'num','post_date');
$firstDate=$currentDate=key($dates);
end($dates);
$lastDate=key($dates);
$result=array();
while(true)
{
if(isset($dates[$currentDate]))
{
$result[]=array('post_date'=>$currentDate,'num'=>$dates[$currentDate]);
}
else
{
$result[]=array('post_date'=>$currentDate,'num'=>0);
}
if($currentDate==$lastDate)
{
break;
}
$dateTimeObject= new DateTime($currentDate);
$dateTimeObject->add(new DateInterval("P1D"));
$currentDate = $dateTimeObject->format("Y-m-d");
}
print_r($result);
Try this code.If the dates are not in order then also this code works. I have added comment in code for understanding
<?php
$array = array(
array(
"post_date"=>"2017-07-22",
"num" =>1
),
array(
"post_date"=>"2017-07-24",
"num" =>2
),
array(
"post_date"=>"2017-07-26",
"num" =>5
),
);
$total = count($array);
$check_dates = array_column($array, "post_date"); //array of dates
asort($check_dates); //sort array by dates and keep keys
$start_date = reset($check_dates); //minimum date
$end_date = end($check_dates); //maximum date
$current_date = $start_date; //set current date to start date
$new_array = array(); //this will be your final array
while (strtotime($current_date) <= strtotime($end_date)) {
$search_val = array_search($current_date, $check_dates);
if($search_val > 0 || $search_val === 0)
{
$new_array[] = $array[$search_val];
}
else
{
$tmp_array=["post_date"=>$current_date,"num"=>0];
$new_array[] = $tmp_array;
}
$current_date = date("Y-m-d",strtotime('+1 day',strtotime($current_date))); //change current date
}
print_r($new_array);
You could define an array with the increased size which is capable of containing the whole dataset. You then could push all elements in it, and once you do that, using strtotime, you could sort the array to be as you wish.
<?php
$arr1 = $your_initial_array;
$arr2 = array_push($arr1, $your_values);
$arr3 = array();
$topop = 0;
for($x = 0; $x < count($arr2); $x++) {
for($i = 0; $i < count($arr2); $i++) {
if(strtotime($arr2[$i]['post_date'] > $latest) { // or < if you want
$topop = $i;
}
}
array_push($arr3, $arr2[$topop]);
unset($arr2[$topop]);
}
You repeat it so many times your array contains elements to be sure you have the right succession. Hope this helps!
Related
I am trying to loop through an array and calculate each value with next one. The data is like
[
['rate' => 1000, 'date' => '2017-07-10'],
['rate' => 2000, 'date' => '2017-08-14'],
['rate' => 3000, 'date' => '2017-08-18'],
['rate' => 1000, 'date' => '2017-07-23']
]
I have this [edited, following an example from another question in stackoverflow]:
#foreach ($users as $user)
#if ($user->admin_id == $active_user) // filtering users under this admin
#foreach ($userbillings as $userbilling)
#if($userbilling->user_id == $user->id) // filtering users
<?php
$count = count($userbilling->created_at);
$rates[] = $userbilling->rate;
$diff = 0;
for ($i=0; $i < $count; $i++) {
if (isset($rates[$i + 1])) {
$thisValue = $rates[$i];
$nextValue = $rates[$i + 1];
$diff = $nextValue - $thisValue;
}
}
echo $diff;
?>
#endif
#endforeach
#endif
#endforeach
This gives me result: 1000 2000 3000 1000 3000
What I want to achieve is to subtract first item from second, second item from third, third item from forth and so on, until it reaches to the last item. For last item, I want to keep the whole number.
I understand that I need to use array and loop here, and I have tried different ways for past 2 weeks, but cannot get even close.
Please suggest me how to make it work, or give me a guideline how I should proceed. I have searched plenty of questions here, but could not find anything right for my problem. If there is any, please suggest me the link.
You haven't specified your preferred output but assuming that you want to end up with an array result of the calculations for all pairs, plus the last element as-is, this should get you on the right track.
I would also second a comment above - do not do this sort of logic in a view as it belongs in a controller or somewhere like a service. Keep your views as simple as possible.
Not tested so please do so yourself:
<?php
$periods = [
['rate' => 1000, 'date' => '2017-07-14'],
['rate' => 3000, 'date' => '2017-08-18'],
['rate' => 2000, 'date' => '2017-08-10'],
['rate' => 3000, 'date' => '2017-08-15'],
['rate' => 1000, 'date' => '2017-08-23'],
];
$lastPeriod = count($periods) - 1;
$ratesForPeriods = [];
foreach ($periods as $index => $currentPeriod) {
if ($index === $lastPeriod) {
$ratesForPeriods[] = $currentPeriod; // add the last as-is
} else {
$nextPeriod = $periods[$index + 1];
$currentDate = new DateTime($currentPeriod['date']);
$interval = $currentDate->diff(new DateTime($nextPeriod['date']));
$ratesForPeriods[] = [
'from' => $currentPeriod['date'],
'to' => $nextPeriod['date'],
'rate' => $currentPeriod['rate'],
'days' => $interval->days,
'total' => $interval->days * $currentPeriod['rate'],
];
}
}
print_r($ratesForPeriods);
Yields:
Array
(
[0] => Array
(
[from] => 2017-07-14
[to] => 2017-08-18
[rate] => 1000
[days] => 35
[total] => 35000
)
[1] => Array
(
[from] => 2017-08-18
[to] => 2017-08-10
[rate] => 3000
[days] => 8
[total] => 24000
)
[2] => Array
(
[from] => 2017-08-10
[to] => 2017-08-15
[rate] => 2000
[days] => 5
[total] => 10000
)
[3] => Array
(
[from] => 2017-08-15
[to] => 2017-08-23
[rate] => 3000
[days] => 8
[total] => 24000
)
[4] => Array
(
[rate] => 1000
[date] => 2017-08-23
)
)
Hope this helps :)
Your question is not clear, but here is an example that might help you!
use array_slice() & array_sum()
$array = array( "0"=>1,"1"=>1,"2"=>5,"3"=>1,"4"=>1,"7"=>1,"8"=>3,"9"=>1);
$keys = array_keys($array);
$array = array_values($array);
$newArr = array();
foreach ($array as $key=>$val) {
$newArr[] = array_sum(array_slice($array, 0, $key+1));
}
$newArr = array_combine($keys, $newArr);
print '<pre>';
print_r($newArr);
print '</pre>';
Reference:
array_slice()
array_sum()
array_combine()
array_keys()
You can access the next item in foreach loop like following code :
foreach ($items as $key => $item)
{
echo !empty($items[$key+1]) ? ($items[$key+1]->rate - $item->rate) : $itema->rate;
}
Given an array of arrays like this:
$array = array(
0 => array (
0 => 35,
1 => 30,
2 => 39
),
1 => array (
0 => 20,
1 => 12,
2 => 5
),
...
n => array (
0 => 10,
1 => 15,
2 => 7
),
);
I have the need to find the entry in the array which is closer to given parameters
find($a, $b, $c) {
//return the closer entry to the input
}
For closer entry I mean the entry which has closer values to the ones gave in input, e.g. passing (19, 13, 3) it should return $array[1]
The way in which I do the calculation at the moment is looping through the whole array, keeping a variable $distance which starts from -1, and a temporary $result variable. For each element I calculate the distance
$dist = abs( subarray[0] - $a ) + abs ( subarray[1] - $b ) + abs( subarray[2] - $c )
and if the calculated distance is equal to -1 or lower than the variable $distance which is out of the loop, I assign the new distance to the varaible and I save the corresponding array in the $result variable. At the end of the loop I end up having the value I need.
Also, one of the values can be empty: e.g. (19, 13, false) should still return $array[1] and the calculation should then ignore the missing parameter - in this case the distance is calculated as
$dist = abs( subarray[0] - $a ) + abs ( subarray[1] - $b );
ignoring the values of subarray[2] and $c.
The problem is, even if my code is working, it took too much time to execute as the size of the array can easily go up to many hundred thousands elements. We are still talking about milliseconds, but for various reasons this is still unacceptable.
Is there a more effective way to do this search in order to save some time?
A custom function - maybe there is a better way but check it out :
In a few words :
Search all the items and find in percentage the difference between the number it checks($mArray[0...3]) and the number you gave($mNumbersToFind[0...3]. Add all the three number's (of each element) possibilities - find the max - keep the position and return the array.
$array = array(
array (
0 => 13,
1 => 15,
2 => 4
),
array (
0 => 20,
1 => 12,
2 => 5
),
array (
0 => 13,
1 => 3,
2 => 15
),
);
$mNumbersToFind = array(13,3,3);
$mFoundArray = find($mNumbersToFind, $array);
echo "mFinalArray : <pre>";
print_r($mFoundArray);
function find($mNumbersToFind, $mArray){
$mPossibilityMax = count($mNumbersToFind);
$mBiggestPossibilityElementPosition = 0;
$mBiggestPossibilityUntilNow = 0;
foreach($mArray as $index => $current){
$maxPossibility = 0;
foreach($current as $subindex => $subcurrent){
$mTempArray[$index][$subindex]['value'] = $subcurrent - $mNumbersToFind[$subindex];
$percentChange = (1 - $mTempArray[$index][$subindex]['value'] / $subcurrent) * 100;
$mTempArray[$index][$subindex]['possibility'] = $percentChange;
$maxPossibility += $percentChange/$mPossibilityMax;
}
$mTempArray[$index]['final_possibility'] = $maxPossibility;
if($maxPossibility > $mBiggestPossibilityUntilNow){
$mBiggestPossibilityUntilNow = $maxPossibility;
$mBiggestPossibilityElementPosition = $index;
}
}
echo "mTempArray : <pre>"; // Remove this - it's just for debug
print_r($mTempArray); // Remove this - it's just for debug
return $mArray[$mBiggestPossibilityElementPosition];
}
Debug Output ($mTempArray) :
mTempArray :
Array
(
[0] => Array
(
[0] => Array
(
[value] => 0
[possibility] => 100
)
[1] => Array
(
[value] => 12
[possibility] => 20
)
[2] => Array
(
[value] => 1
[possibility] => 75
)
[final_possibility] => 65
)
[1] => Array
(
[0] => Array
(
[value] => 7
[possibility] => 65
)
[1] => Array
(
[value] => 9
[possibility] => 25
)
[2] => Array
(
[value] => 2
[possibility] => 60
)
[final_possibility] => 50
)
[2] => Array
(
[0] => Array
(
[value] => 0
[possibility] => 100
)
[1] => Array
(
[value] => 0
[possibility] => 100
)
[2] => Array
(
[value] => 12
[possibility] => 20
)
[final_possibility] => 73.333333333333
)
)
Final Output :
mFinalArray :
Array
(
[0] => 13
[1] => 3
[2] => 15
)
I basically used a concept of proximity (lesser distance total for each array) and returned that. The code was made in a way that can improve very well in so many routines.
PS: I didn't used advanced functions or other things because you are concerned about performance issues. It's most simplest routine I could did in a short period of time.
$array = array(
0 => array (
0 => 35,
1 => 30,
2 => 39
),
1 => array (
0 => 20,
1 => 12,
2 => 5
),
);
$user = array(19,13,3);
function find($referencial, $input){
$totalRef = count($referencial);
if (is_array($referencial)){
for ($i = 0; $i < $totalRef; $i++) {
if (is_array($referencial[$i])){
$totalSubRef = count($referencial[$i]);
$proximity = array();
for ($j = 0; $j < $totalSubRef; $j++) {
$proximity[$i] += abs($referencial[$i][$j] - $input[$j]);
}
if ($i > 0){
if ($maxProximity['distance'] > $proximity[$i]) {
$maxProximity['distance'] = $proximity[$i];
$maxProximity['index'] = $i;
}
} else {
$maxProximity['distance'] = $proximity[$i];
$maxProximity['index'] = $i;
}
}
}
return $maxProximity;
} else {
exit('Unexpected referencial. Must be an array.');
}
}
$found = find($array, $user);
print_r($found);
//Array ( [distance] => 4 [index] => 1 )
print_r($array[$found['index']]);
// Array ( [0] => 20 [1] => 12 [2] => 5 )
I walk around here with some hesitation, I have passed an array with sub elements (so to speak) and I need three random values but these are obtained without repeating.
The array is as follows:
Array
(
[0] => Array
(
[uid] => 1
[ticket_code] => 0oreb8yo
)
[1] => Array
(
[uid] => 1
[ticket_code] => 2oeii8hm
)
[2] => Array
(
[uid] => 1
[ticket_code] => m0dwtjiw
)
[3] => Array
(
[uid] => 1
[ticket_code] => q6c7cymb
)
[4] => Array
(
[uid] => 1
[ticket_code] => zyqhm5bj
)
[5] => Array
(
[uid] => 1
[ticket_code] => amdqzjpi
)
[6] => Array
(
[uid] => 2
[ticket_code] => tzql7l42
)
[7] => Array
(
[uid] => 2
[ticket_code] => gap0r6vf
)
[8] => Array
(
[uid] => 2
[ticket_code] => ypqum5yz
)
[9] => Array
(
[uid] => 4
[ticket_code] => smupluac
)
[10] => Array
(
[uid] => 4
[ticket_code] => 9d8jsha7
)
[11] => Array
(
[uid] => 5
[ticket_code] => 6hdnja42
)
)
And I need you to get 3 "ticket_code" but no right to repeat the "uid".
I've been on trying as follows, but also repeats the "uid".
$ticketsWinners = array();
for ($i=0; $i < 3; $i++) {
$aux = array_rand($allTickets);
$aux2 = $allTickets[$aux]['uid'];
$ticketsWinners[] = array(
'uid' => $aux2,
'ticket_code' => $allTickets[$aux]['ticket_code']
);
}
Any way to do it without repeats?
We thank you in advance if anyone knows of something ^^
Try something like:
$ticketsWinners = array();
while (sizeof($ticketsWinners) < 3) {
$aux = array_rand($allTickets);
// array_rand return array of keys so you need first value only
$uid = $allTickets[$aux[0]]['uid']
// add uid as a key so ass not tot check all $allTickets values
if (!isset($ticketsWinners[$uid]))
$ticketsWinners[$uid] = $allTickets[$aux[0]];
}
// if you need $allTickets back to numeric keys [0, 1, 2]
$allTickets = array_values($allTickets);
if you're afraid of infinite loops (that can take place really) then try this:
$ticketsWinners = array();
// shuffle array before checking
shuffle($allTickets);
foreach ($allTickets as $tick_data) {
$uid = $tick_data['uid'];
if (!isset($ticketsWinners[$uid]))
$ticketsWinners[$uid] = $tick_data;
if (sizeof($ticketsWinners) == 3)
break;
}
Here in worst case you check $allTickets array and get winners of size <= 3.
Try this:
$ticketsWinners = array();
$ticketUid = array();
for ($i=0; $i < 3; $i++) {
$aux = array_rand($allTickets);
$aux2 = $allTickets[$aux]['uid'];
if(! in_array($aux2, $ticketUid)) {
$ticketUid[$i] = $aux2;
$ticketsWinners[] = array(
'uid' => $aux2,
'ticket_code' => $allTickets[$aux]['ticket_code']
);
} else {
$i--;
}
}
this structure would be better ( added benefit of ticket numbers being unique )
$tickets = Array
(
'0oreb8yo' => 1,
'2oeii8hm' => 1,
'm0dwtjiw' => 1,
'q6c7cymb' => 1,
'zyqhm5bj' => 1,
'amdqzjpi' => 1,
'tzql7l42' => 2,
'gap0r6vf' => 2,
'ypqum5yz' => 2,
'smupluac' => 3,
'9d8jsha7' => 4,
'6hdnja42' => 5,
);
$winners = array();
$picks = 3;
for($i = 0; $i < $picks; $i++){
if(count($tickets) == 0 ){
break; //or error -- shouldn't need this unless picks exceed uids
}
$ticket = array_rand($tickets);
$winner = $tickets[$ticket];
$winners[] = $winner;
$tickets = array_filter($tickets, function($item) use ($winner){
return $winner != $item;
});
}
echo '<pre>';
var_export($winners);
outputs
array (
0 => 2,
1 => 1,
2 => 4,
)
array (
0 => 2,
1 => 1,
2 => 3,
)
array (
0 => 1,
1 => 3,
2 => 2,
)
unlike the while option, this will reduce the operations for each loop of the for loop by reducing the ticket array by the uid. It's also the only way to insure your not always pulling out a user with tickets, what if user 1 bought 90% of the tickets, you'd loop on him 90% of the time, in any case you have to reduce the ticket array by winners if they can win only once. In essence you remove each uid from the list when they win. You can also be sure that each ticket has the same chance to win ( as well as array_rand is random that is ) - they all have equal footing.
ticket array reduction
after loop1
array (
'tzql7l42' => 2,
'gap0r6vf' => 2,
'ypqum5yz' => 2,
'smupluac' => 3,
'9d8jsha7' => 4,
'6hdnja42' => 5,
)
after loop2
array (
'smupluac' => 3,
'9d8jsha7' => 4,
'6hdnja42' => 5,
)
after loop3
array (
'smupluac' => 3,
'6hdnja42' => 5,
)
winners
array (
0 => 1,
1 => 2,
2 => 4,
)
to return both the uid and wining ticket change
$winners[] = $winner;
to
$winners[$ticket] = $tickets[$ticket];
now winners will be, just like the input array
ticketnumber => uid
ticket is the key ( which is the ticket ) and winner is the value ( which is the uid )
This is how $myArray looks like:
Array
(
[0] => Array
(
[month] => 1
[atual] => 0.00
)
[1] => Array
(
[month] => 2
[atual] => 11970.99
)
[2] => Array
(
[month] => 3
[atual] => 2888.00
)
[3] => Array
(
[month] => 5
[atual] => 1500.00
)
)
I want to "fill the gaps" of the months. That is, for those months, where we have no data (4,6,8,9,10,11,12), I want the [atual] to be zero.
I tried:
$novo=array();
for ($i=1; $i <=12 ; $i++) {
$mes=$myArray[$i-1]['month'];
$atual=$myArray[$i-1]['atual'];
if(!$mes){
$novo[$i]=0;
} else{
$novo[$i]=$atual;
}
};
But this is returning:
Array
(
[1] => 0.00
[2] => 11970.99
[3] => 2888.00
[4] => 1500.00
[5] => 0
[6] => 0
[7] => 0
[8] => 0
[9] => 0
[10] => 0
[11] => 0
[12] => 0
)
[edit] now i see you have another problem, your $myArray indexes aren't matching the months.
$myArray(
array('month' => 1, 'atual' => 0.00),
array('month' => 2, 'atual' => 11970.99),
array('month' => 3, 'atual' => 2888.00),
array('month' => 5, 'atual' => 1500.00)
)
for($i = 1; $i <= 12; $i++){
$novo[$i] = 0;
}
foreach($myArray as $item){
$novo[$item['month']] = $item['atual'];
}
print_r($novo);
This worked:
$novo=array_fill(1,12,0);
for ($i=1; $i <=12 ; $i++) {
$mes=$myArray[$i-1]['month'];
$atual=$myArray[$i-1]['atual'];
$novo[$mes]=$atual;
};
With this code you get the month 1 in position 1 (not in position 0);
Also you only search in the array one time.
It's not a beautiful solution but...
$my_array = array(
array('month'=>3,'actual'=>100)
);
$results =array();
for($i=1;$i<13;$i++){
$results[$i] = 0;
}
foreach($my_array as $a){
$results[$a['month']] = $a['actual'];
}
print_r($results);
PHP has several functions that deal with sorting arrays, and here is a comparison of array's sorting functions
I didn't fully understand your question in the first response. This code should work for you. First we will create a temporary array just to hold the month and the data in an accessible format. Then we create your array :
$temp=array();
// Populate the temp array
foreach ($myArray as $row) {
if (is_array($row) && isset($row["month"])) {
$temp[$row["month"]] = $row["atual"];
}
}
// Create novo array
for ($i=0; $i <12 ; $i++) {
$novo[$i]["month"] = $i+1;
if (array_key_exists($i+1, $temp)) {
$novo[$i]['atual'] = $temp[$i+1];
} else {
$novo[$i]['atual'] = 0;
}
}
This question already has answers here:
How can I sort arrays and data in PHP?
(14 answers)
Closed 9 years ago.
I have an array of data comprising a 'customer' and a 'Total'. (example below). It is drawn from two different databases.
I need a way to sort the array, based on the Total field, so that the Largest Total is at the top. But so far every thing I have tried has resulted in it assuming that 5 is larger than 32
[5, 32, 25, 16, 11]
What's the easiest way to achieve this? I tried adding intval() to the strcmp function, but it made no difference?
$arrayName = array();
$arrayName[] = array ('customer' => 'Customer1', 'Total' => 25);
$arrayName[] = array ('customer' => 'Customer2', 'Total' => 16);
$arrayName[] = array ('customer' => 'Customer3', 'Total' => 32);
$arrayName[] = array ('customer' => 'Customer4', 'Total' => 5);
$arrayName[] = array ('customer' => 'Customer5', 'Total' => 11);
print_r($arrayName);
print "</br>";
//Sort the Arrray by Total
function arrSort1($b, $a)
{
return strcmp($a['Total']), $b['Total']);
};
usort($arrayName, "arrSort1");
print_r($arrayName);
You're comparing by string but you really want to compare by numeric value. Try:
function arrSort1($b, $a)
{
if ($a['Total'] > $b['Total']) {
return 1;
} else if ($a['Total'] < $b['Total']) {
return -1;
}
return 0;
}
The sorted array will look like this:
Array
(
[0] => Array
(
[customer] => Customer3
[Total] => 32
)
[1] => Array
(
[customer] => Customer1
[Total] => 25
)
[2] => Array
(
[customer] => Customer2
[Total] => 16
)
[3] => Array
(
[customer] => Customer5
[Total] => 11
)
[4] => Array
(
[customer] => Customer4
[Total] => 5
)
)