I'm new to this community and php in general.
Please bear with me as I try to explain my beginner's problem.

My goal is to run a database query to retrieve 10 rows based on latitude/longitude from a column named "WOONPLAATS"
in a table named "POSTCODES" and to store all results into a single variable to feed it into a second database query later on.

With every
$nearbylocations = $arr['WOONPLAATS']; you are overwriting the variable $nearbylocations.

You could for example use an array, to store all of the values. Declare
$nearbylocations = array(); somewhere before the while loop and use
$nearbylocations []= $arr['WOONPLAATS']; to put it all in. In order to get the format you specified, you can then use
echo implode(" ", $nearbylocations);

Instead of an array you can also use a string and concat the new values in, like

$nearbylocations .= $arr['WOONPLAATS']." ";
This will immediately get you the format you specified, except for that one space you will have at the end, if you don't do anything against it.