It would be really cool if we had a built-in sort function that let us specify our own function for comparing objects (similar to c or java sorting methods).
example:
PHP Code:
temp.arr = {3, 4, 1, 22, 14, 42, 1337};
temp.func = function(a, b) { // should return <0 if (a < b), >0 if (a > b), or ==0 if (a == b)
// do whatever you want to compare a and b
// ex:
return a - b;
};
temp.arr.sort(..., temp.func); // would sort the array using my compare function
I'm not sure if the above is syntactically correct...probably not, but you get the idea.
Actually, I might try to do something like this later when I'm not busy, but built-in would be better!
edit: bubble sort is a terrible sorting algorithm, and if you don't need to specify a specific order, you should stick to built-in sorting which probably uses quicksort or some other O(nlogn) sorting algorithm.