I have an array such as:
Array
(
[0] => Array
(
[id] => 2
[type] => comment
[text] => hey
[datetime] => 20
You can simply solve this problem using usort() with callback function. No need to write any custom function.
$your_date_field_name = 'datetime';
usort($your_given_array_name, function ($a, $b) use (&$your_date_field_name) {
return strtotime($a[$your_date_field_name]) - strtotime($b[$your_date_field_name]);
});