0

PHP best practice - arrays to javascript

My website has a php array. I want to be able to use the same array in a javscript file. I've done some searching and the best I can come up with is to add this to one of my .php files: ?><script>var jArray = <?php echo json_encode($myPHParray); ?>;</script><?php I've tested this and I'm happy the information is there, however it seems very ugly. Is there a more eloquent way to read PHP from JS?

26th Jul 2018, 3:58 PM
Greg Hurlock
Greg Hurlock - avatar
1 Antwort
- 1
Share your data in myphparay.
26th Jul 2018, 4:03 PM
ᴋᵘⁿᵃˡ
ᴋᵘⁿᵃˡ - avatar