In the code below, I'm assuming your coordinate objects are just stored as a two element array (both for the $center parameter and the coordinates in the $coordinateArray). If not it should be fairly obvious what you need to change.
function getCoordinatesWithinRadius ($coordinateArray, $center, $radius) {
$resultArray= array();
$lat1 = $center[0];
$long1 = $center[1];
foreach ($coordinateArray as $coordinate) {
$lat2 = $coordinate[0];
$long2 = $coordinate[1];
$distance = 3959 * acos(cos(radians($lat1)) * cos(radians($lat2)) * cos(radians($long2) - radians($long1)) + sin(radians($lat1)) * sin(radians($lat2)));
if ($distance < $radius) $resultArray[] = $coordinate;
}
return $resultArray;
}
The code just loops through all the coordinates, calculates the distance from the center point, and if its less than the given $radius, adds the coordinate to the $resultArray.
I haven't checked the $distance calcuation - that's basically just cut and paste from your mysql query, so I'm assuming that's correct.
Also the above code assumes the existence of a radians function. If you don't have one, you could add one like this:
function radians($deg) {
return $deg * M_PI / 180;
}
That's assuming the coordinates are in degrees.