Title: Parsing PHP array in Javascript array in JS file.
Last modified: August 19, 2016

---

# Parsing PHP array in Javascript array in JS file.

 *  [Vrefr](https://wordpress.org/support/users/vrefr/)
 * (@vrefr)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/parsing-php-array-in-javascript-array-in-js-file/)
 * I’m trying to create markers in google map JS API V3.
    Each post in blog has 
   a variable with city name that is collected to an array $cities. the code in 
   gmap.js, that is loaded in header of myblog uses array **cities**:
 *     ```
       google.maps.event.addListener(mgr, 'loaded', function() {
       // These markers will only be visible between zoom level 1 and 7
               mgr.addMarkers(cities, 1, 9);
       // These markers will be visible at zoom level 6 and deeper
               mgr.addMarkers(dotss, 10);
       // Making the MarkerManager add the markers to the map
               mgr.refresh();
               });
       ```
   
 * PHP code in loop.php returns me needed data in the array,
 *     ```
       <script>
       var cities = [];
       <?php
       foreach( $clean_cities as $city_r ) {
       echo "cities.push(" . $city_r . ");\n";
       }
       ?>
       </script>
       ```
   
 * the result is
    `var cities = [kiev,kharkov,lvov,odessa];` If i write or assemble
   in the same way this array directly in gmap.js everything works perfectly. But
   if I generate or manually write this array in page body – nothing works, at the
   same time other variables and arrays (such as latitude and longitude) defined
   in page body are perfectly accepted by gmap.js.
 * Does anybody know what’s the problem in here?
    Thanks in advance for answer.

The topic ‘Parsing PHP array in Javascript array in JS file.’ is closed to new replies.

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Vrefr](https://wordpress.org/support/users/vrefr/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/parsing-php-array-in-javascript-array-in-js-file/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
