I've found some similar question on StackOverflow, but my problem is different. I'll try to explain more clear possible. First of all the array structure: $appointment
Array (
[id_users_provider] => 85
[start_datetime] => 2015-11-15 17:15:00
[end_datetime] => 2015-11-15 17:15:00
[notes] =>
[is_unavailable] =>
[id_users_customer] => 87
[id_services] => 15
)
Array (
[id_users_provider] => 85
[start_datetime] => 2015-11-15 17:15:00
[end_datetime] => 2015-11-15 17:15:00
[notes] =>
[is_unavailable] =>
[id_users_customer] => 87
[id_services] => 13
)
How you can see I've two array included in the $appointment variable. Now I want get the end of the last array, in this case the array with id_services: 13. I actually execute an iteration through the appointment['id_services'].
Like this:
foreach($appointment['id_services'] as $services)
{
print_r(end($appointment));
}
but this return me:
15
13
and this is wrong, 'cause I want get only 13 in this case. How I can do that?
The main problem is to check inside the foreach loop if the actual $services is the last key of the last array inside the foreach loop.
count()function to know how many elements there are inside each array, and then just substract one to that number and you will get the last element