Title: Pass PHP array to Javascript array: Json, join, implode
Last modified: August 20, 2016

---

# Pass PHP array to Javascript array: Json, join, implode

 *  [rajvid9](https://wordpress.org/support/users/rajvid9/)
 * (@rajvid9)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/pass-php-array-to-javascript-array-json-join-implode/)
 * I am working on a plugin and I need to pass PHP array to Javascript array. I 
   have tried using join(), implode() and even Json_encode. But, the wordpress is
   not displaying any value.
 * When using join(), I used the code:
 *     ```
       <?php
       $php1 = array(1,2,3);
   
       ?>
       <script language='Javascript'>
       var lat = ["<?php echo join("\", \"", $php1); ?>"];
       document.write(lat[1]);
       </script>
       ```
   
 * If used on localhost(without wordpress), the above code provides a valid output.
   But, somehow, its not working on WordPress. The “apache error log” show this 
   message:
 * PHP Warning: join() [function.join]: Invalid arguments passed in \wp-content\
   plugins\Animation\animation.php on line 129, referer: [http://localhost/Website/wp-admin/options-general.php?page=js](http://localhost/Website/wp-admin/options-general.php?page=js)
 * Same is the case with implode(). Server error log shows same above warning for
   implode().
 * Then I tried for json_encode using the code below:
 *     ```
       var lat = <?php echo json_encode($php1); ?>;
       ```
   
 * But the no value is returned.
 * Please guide me through this. I appreciate any help. It would be great if you
   help me in passing this PHP array to javascript array.

The topic ‘Pass PHP array to Javascript array: Json, join, implode’ is closed to
new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [rajvid9](https://wordpress.org/support/users/rajvid9/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/pass-php-array-to-javascript-array-json-join-implode/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
