sort
Sequentially Rename All Image Files In A Directory With PHP
Mon, 03/02/2009 - 12:36 | by philipnorton42The following function will rename all of the image files in a directory to be sequential. The parameters are the path of the directory that the files are in and the name of a function that will be used to sort the array of files through the PHP usort() function.
Force Sorting Of VARCHAR Data In MySQL
Thu, 09/18/2008 - 09:05 | by philipnorton42If you find that you are having trouble sorting data in a VARCHAR column in a MySQL database then you can try the following trick.
Lets say that you had the values 1,200,30,4000 and 5 and that you inserted them into the database in that order. When the following query is run on this data:
SELECT numbers FROM table ORDER BY numbers;
The following output is seen.
Randomise JavaScript Array
Fri, 07/04/2008 - 08:43 | by philipnorton42Randomising a JavaScript array can be done in one or two ways. The easy way is to create a function that returns a random number and then use the sort() function of the Array object to sort the array by a random value.
Array Sorting Algorithms In PHP
Tue, 04/01/2008 - 15:04 | by philipnorton42There are many ways to sort an array in PHP, the easiest being to use the sort() function built into PHP. This sort function is quick but has it's limitations, especially when sorting things like dates as PHP usually guesses which value is higher than the other and can produce odd results. However, there are plenty of sorting algorithms available than can allow you to sort an array in any way you want.
The simplest of these is called the bubble sort. Here is a function that will sort an array of values using the bubble sort algorithm.