+ 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.)
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š
+ 20
echo "<script>arr='".implode(",",$array)."'.split(',');</script>";
(...not tested...)
+ 1
@Yaroslav Pieskov
That's it :)
___
ŠŠ¾ŠæŠµŃ Š² ŃŠµŠ¼ ŠŗŠ¾ŃŃŠŗ...Š²Š¾Š·Š²ŃŠ°ŃŠ°Š» Š² ŠæŠµŃŠµŠ¼ŠµŠ½Š½ŃŃ Š² php Š½Š°ŠŗŠ¾Š¹ ŃŠ¾...
Š²Š¼ŠµŃŃŠ¾ Š²ŃŠ²Š¾Š“Š°...