D
D
Dmitry Passov2017-06-02 14:51:09
JSON
Dmitry Passov, 2017-06-02 14:51:09

How to get out of loop in json?

Greetings.
There is this simple array traversal:
foreach ($cities as $city) {
if ($city['country_code'] == "$iata")
foreach ($city as $key => $value) {
$lat = $city ['coordinates']['lat'];
$lng = $city['coordinates']['lon'];
}
}
How to convert the result of the work to json?
{"lat":value,"lng":value}, {"lat":value,"lng":value}, etc.
It is clear that in the end using json_encode, but how exactly to pass the values?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2017-06-02
@devspec

var j = JSON.stringify(arr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question