I have an array which contain datetime
array(3) {
[1368090995]=>
object(stdClass)#375 (1) {
["submitted"]=>
string(10) "1368090995"
}
[1368091032]=>
object(stdClass)#376 (1) {
["submitted"]=>
string(10) "1368091032"
}
[1368091070]=>
object(stdClass)#372 (1) {
["submitted"]=>
string(10) "1368091070"
}
}
I want to get the latest time from this array.
How can I compare the datatime from array?
As you have the timestamps as keys you could quite simply do this
$timestamps = array_keys($your_array);
$latest = max($timestamps);
array_keys()
returns an array of all the keys in your input array max()
accepts an array of numbers and returns the highest number and therefore in this instance the latest time
sort($array);
print_r(array_shift($array));
Based on your example array of obejcts, you could use
$latest = max(array_keys($array));