If the question is sorting the data list, I would use the function usort
.
She orders a array
according to a comparison made by a callback
.
Then see what beauty (a date has been modified to check that the ordering works):
$locados = array(
'2016-02-01', '2016-01-02', '2016-01-03', '2016-01-06',
'2016-01-07', '2016-01-08'
);
usort($locados, function ($a, $b)
{
return strtotime($a) - strtotime($b);
});
pr($locados);
The result will be:
Array
(
[0] => 2016-01-02
[1] => 2016-01-03
[2] => 2016-01-06
[3] => 2016-01-07
[4] => 2016-01-08
[5] => 2016-02-01
)
To take the last and first date, we can do so:
function first($arr)
{
return reset($arr);
}
function last($arr)
{
return end($arr);
}
first($locados); // 2016-01-02
last($locados); // 2016-02-01
If you don’t understand why to create new functions to get the last and first element, I suggest you read this answer:
/a/89003/4995
I answered but, rereading again it seems that you are actually trying to split in half and make 2 groups? It has more details than exactly you need?
– Thyago ThySofT
You return so from your database ? Isn’t it something like Person X rented day Y place x day y ? Post your sql or as an example of the table you take this information from
– Gabriel Rodrigues
The reservation table even has the date of Chekin and checkout, the problem is that the customer mismanages the reservations, does not change her status, is always as a new reservation and not as a paid or confirmed reservation, then I have to use the dates of each apartment to make this control of rental periods... unfortunately.
– caiocafardo