0

Is krsort() function suitable for sorting (by reverse order) an array where keys are timestamps? Is there (maybe) another "standard" function for doing this?

$arr = array(); $arr[1327305600] = '87718'; $arr[1327132800] = '87798'; // Dunno if SORT_NUMERIC is really necessary? krsort($arr, SORT_NUMERIC); 
0

2 Answers 2

1

Yes it is perfectly suitable, you should use the SORT_NUMERIC flag. It isn't required as regular sorting will take integers first - but it could prevent future problems.

Sign up to request clarification or add additional context in comments.

2 Comments

What kind of "future problems"? Thanks.
Someone making modifications to other parts of your application that could influence your sorting by automaticly relying on natural sorting.
1

krsort()is fine if the timestamps are the number of seconds (or milliseconds) since an epoch, say, the Unix Epoch (January 1 1970 00:00:00 GMT). SORT_NUMERIC is not necessary if you are sure that all keys are Unix timestamps.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.