How to convert php json to js

藏色散人
Release: 2023-03-06 18:00:02
Original
1570 people have browsed it

php json to js method: first create a PHP sample file; then use "eval("(" '' ")");" to convert json to js array.

How to convert php json to js

Recommended: "PHP Video Tutorial"

php background json to js array

1. String

$this->assign('id',$id);
var health_id = &#39;<?php echo $id;?>&#39;;
Copy after login

2-1 array

$this->assign(&#39;cycle&#39;, ArchivesUtil::CYCLE);
var cycle = eval("(" + &#39;<?php echo json_encode($cycle);?>&#39; + ")");
Copy after login

or

var mobile = "<?php echo $cycle[&#39;mobile&#39;]; ?>";
Copy after login

2-2

$this->assign(&#39;arr&#39;, json_encode($arr));
Var arr = {$arr};
Copy after login

Example: json to js array, traverse key value

How to convert php json to js

--------------------- -------------------------------------------------- --------------------------------------------------

tp5

var info = {$info|raw};
Copy after login

The above is the detailed content of How to convert php json to js. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!