I am trying to generate lat and long cordinates for about a 1000+ locations, I know how to get them in a range and everything but I was wondering if I can do something like this.
for ($i = 0; $i < 10; $i++) { $lat = function () { $float = rand(0, 99999) / 99999; $lat = rand(30, 32); $lat = $lat + $float; return $lat; }; $long = function () { $float = rand(0, 99999) / 99999; $long = rand(74, 76); $long = $long + $float; return $long; }; print_r($lat); } The code didn't throw the desired result instead, I'm getting
closureObject() There's no error but I can't seem to get it to work, any help would be wonderful, I've tried reading the documentation but doesn't explain anything related to this.
Can this work?
print_r()a function definition, so a closure object?print_r($lat());and you should see the result. As others have mentioned, why not just define 2 functions then use those functions in your loop? (Could even be 1 function if you see the pattern in them).