Home > Backend Development > PHP Tutorial > How to generate an array in PHP and then pass it to js, ​​PHP generates an array in js_PHP tutorial

How to generate an array in PHP and then pass it to js, ​​PHP generates an array in js_PHP tutorial

WBOY
Release: 2016-07-13 10:21:14
Original
901 people have browsed it

PHP generates an array and then passes it to js. PHP generates an array js

<script type="text/javascript">
  var slist = '<&#63;php echo urlencode(json_encode($data['arr']));&#63;>';
  var list = eval(decodeURIComponent(slist));
  drawGpsMap(list);
</script>
Copy after login

How to pass the value of php array to javascript array?

cannot be passed directly, but you can use js ajax to dynamically call the php array value when the page is loaded
or assign the array value processed with php as a string to the html hidden control first, and then use js code to call hidden value
In addition, I think that if your data does not change frequently, it is better to use php to generate a .js file that defines the array and then file it.

How to pass values ​​in PHP array to JS

Is this what you said?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/860470.htmlTechArticlePHP generates an array and then passes it to js. PHP generates an array js script type="text/javascript" var slist = 'php echo urlencode(json_encode($data['arr']));'; var list = eval(decodeURICompone...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template