Title: Pass array PHP code to JS code
Last modified: April 29, 2022

---

# Pass array PHP code to JS code

 *  [akmiecik](https://wordpress.org/support/users/akmiecik/)
 * (@akmiecik)
 * [4 years ago](https://wordpress.org/support/topic/pass-array-php-code-to-js-code/)
 * I have a piece of PHP code working fine and dandy but I need to pass an array
   to JS code for the next step.
 * If I put a script code at the end of the PHP code I can get the array passed 
   to that JS script but it does not pass if that script is a Code Manager LS piece
   of code.
 * Here’s the array passing script. I use script tags after the ?> in the PHP piece
   of code but not in the JS piece of code.
 *     ```
       <script>
            var passArray = <?php echo '["' . implode('", "', $php_array) . '"]' ?>;
            document.write(passedArray[0]);
       </script>
       ```
   
 * Thanks.

The topic ‘Pass array PHP code to JS code’ is closed to new replies.

 * ![](https://ps.w.org/code-manager/assets/icon-128x128.png?rev=2392773)
 * [Code Manager](https://wordpress.org/plugins/code-manager/)
 * [Support Threads](https://wordpress.org/support/plugin/code-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/code-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-manager/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [akmiecik](https://wordpress.org/support/users/akmiecik/)
 * Last activity: [4 years ago](https://wordpress.org/support/topic/pass-array-php-code-to-js-code/)
 * Status: not resolved