{"id":15604491,"date":"2022-04-29T22:06:31","date_gmt":"2022-04-29T22:06:31","guid":{"rendered":"https:\/\/wordpress.org\/support\/?post_type=topic&#038;p=15604491"},"modified":"2022-04-29T22:13:46","modified_gmt":"2022-04-29T22:13:46","slug":"pass-array-php-code-to-js-code","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/pass-array-php-code-to-js-code\/","title":{"rendered":"Pass array PHP code to JS code"},"content":{"rendered":"<p>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.<\/p>\n<p>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.<\/p>\n<p>Here&#8217;s the array passing script.  I use script tags after the ?&gt; in the PHP piece of code but not in the JS piece of code.<\/p>\n<pre><code>&lt;script&gt;\n     var passArray = &lt;?php echo &#039;[&quot;&#039; . implode(&#039;&quot;, &quot;&#039;, $php_array) . &#039;&quot;]&#039; ?&gt;;\n     document.write(passedArray[0]);\n&lt;\/script&gt;<\/code><\/pre>\n<p>Thanks.<\/p>\n","protected":false},"template":"","class_list":["post-15604491","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15604491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15604491\/revisions"}],"predecessor-version":[{"id":15604499,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15604491\/revisions\/15604499"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=15604491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}