i have an array of date in php like
Array
(
[0] => Array
(
[month] => April-2014
[total_booking] => 2
)
[1] => Array
(
[month] => May-2014
[total_booking] => 5
)
[2] => Array
(
[month] => June-2014
[total_booking] => 25
)
[3] => Array
(
[month] => October-2013
[total_booking] => 1
)
[4] => Array
(
[month] => July-2014
[total_booking] => 4
)
)
i want to find the minimum and maximum month from this array. currently i am using foreach()
function and comparing each element. but i think this is not ideal if the array is bigger. is there any other option?
expected output from the above array
minimum:October-2013
maximum :July-2014
update now i have converted this array to following structure
Array
(
[October-2013] => 5
[April-2014] => 2
[June-2014] => 17
[August-2014] => 1
[May-2014] => 4
[July-2014] => 8
)
then for finding minimum and maximum by
natcasesort($testKeys = array_keys($newarray));
echo 'Min: ' . $testKeys[0] . ', max: ' . $testKeys[count($testKeys) - 1] . '<br />';
but i am getting output
Min: October-2013, max: July-2014 .
expected maximum is August-2014
.
can any one find the solution?