View Full Version : Sorting arrays by value

06-15-2005, 11:45 PM
Can anyone help?

Here's my problem: I am working on a OOP module for sorting a mysql result set by distance from a specified zip code. Say I query the database like this: "SELECT id, name, city, state, zip, phone FROM contacts WHERE city= 'Dallas'". I then pass this to the class. For each result returned I used an "array_push" and added a ziplocateddistance to each result array.

Here's what I need help with: I need to sort the array by the ziplocateddistance. That's all! I just need some help. There's no php function that will do this to my knowledge. If anyone can help I would greatly appreciate it! I need to finish this by Saturday.


06-16-2005, 12:07 AM
isn't it just sort() or asort() ? http://uk.php.net/manual/en/function.sort.php

i also do't realy see why you need an array_push... you can just dump the resultset in a 2D-array end then add a new elemet for the distance.

06-16-2005, 12:29 AM
Sorry, I forgot to mention, It's a 3D array.

06-17-2005, 08:51 PM
no problem.

just read the usercomments in the two pages i linked to. there is plenty of examplecode inthere to sort all sorts of arrayw in different ways.