' + ")");" That’s it."/> ' + ")");" That’s it.">

Home >Backend Development >PHP Problem >How to convert php json to js

How to convert php json to js

藏色散人
藏色散人Original
2020-10-16 11:00:151775browse

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;;

2-1 array

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

or

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

2-2

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

Example: json to js array, traverse key value

How to convert php json to js

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

tp5

var info = {$info|raw};

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!

Statement:
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