I have this array:
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
/*
Array
(
[0] => Array
(
[id] => 191
[range] => today
)
[1] => Array
(
[id] => 190
[range] => today
)
[2] => Array
(
[id] => 189
[range] => in last week
)
[3] => Array
(
[id] => 180
[range] => in last week
)
[4] => Array
(
[id] => 170
[range] => in last week <- this
)
)
*/
I'm trying to get the vale of range
which is last item. in this case it is in last week
. Here is my code:
foreach ( $results as $item ) {
$last_range_item = $item[range];
}
My approach should work, but there is a lot of useless processes and overwriting. So is there any better way?