+ 3

How to move array from PHP to JS ?

We have $whole_arr associative array in php, and...we need it to move to wholeArr in js. We can use them both on same page. Any ideas?(exept saving it in invisible element and getting , that's not cool :D) (only using js ,php,html,css if needed.)

22nd Apr 2017, 8:19 PM
Rose Sevenyears
Rose  Sevenyears - avatar
4 Answers
+ 2
<?php $sts = array( "one"=>"one text", "two" => "two text", "three" => "text three" ) ?> <script> var t= <?php echo json_encode($sts);?> console.log(t) </script> works perfectšŸ‘
22nd Apr 2017, 9:17 PM
Yaroslav Pieskov
Yaroslav Pieskov - avatar
+ 20
echo "<script>arr='".implode(",",$array)."'.split(',');</script>"; (...not tested...)
22nd Apr 2017, 8:08 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
@Yaroslav Pieskov That's it :) ___ Š”Š¾ŠæŠµŃ€ Š² чŠµŠ¼ ŠŗŠ¾ŃŃŠŗ...Š²Š¾Š·Š²Ń€Š°Ń‰Š°Š» Š² ŠæŠµŃ€ŠµŠ¼ŠµŠ½Š½ŃƒŃŽ Š² php Š½Š°ŠŗŠ¾Š¹ тŠ¾... Š²Š¼ŠµŃŃ‚Š¾ Š²Ń‹Š²Š¾Š“Š°...
22nd Apr 2017, 9:27 PM
Rose Sevenyears
Rose  Sevenyears - avatar