me long through usort () function problems in the processing of PHP arrays. I want to sort an array with 40-50 elements like "1.1", "2.3", "1.1.2", "3.1", 30, "3.10" ... if I only want to move some elements forward If everything works fine, but if I have an array of 40 elements, the function is very slow - so slow that it overrides the 90-second timeout ...
My code :
function mySort ($ a, $ b) {$ a_arr = explosion (".", $ A); $ B_arr = Explosion (".", $ B); If ($ a_arr [0] & lt; $ b_arr [0]) {return -1; Break;} if ($ a_arr [0]> $ b_arr [0]) {return1; Break; for} ($ i = 0; $ a_arr [$ i] == $ b_arr [$ i]; $ i ++) {if ($ a_arr [$ i + 1] & lt; $ b_arr [$ i + 1]) {return -1; Break;} if $ ($ a_arr [$ i + 1]> $ b_arr [$ i + 1]) {return1; Break;}}} $ sort_array = array ("1.1", "2.3", "1.1.2", "3.1", "30", "3.10"); // Example, I get this data from Database Usage ($ sort_array, "mySort"); ... can someone help, please? Is it possible to solve?
What does your loop do when the values are equal in the array? When two elements of the array are equal, add somewhere to indicate the 0 segment of a place.
This should be done when you are out of the elements of any list (A, B). Because otherwise you will get notice about access to the array-index that does not exist. (Your sample gives such a notice)
No comments:
Post a Comment