How to convert js array to php array: 1. Define the JS array; 2. Add the tags entered by the user to this array; 3. Encode through "encodeURI(tagslist)"; 4. Use UrlDecode decoding; 5. Use the implode function to convert it into a string and store it in the database.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to convert js array to php array?
PHP and JS array conversion
Because it is used in the program and I have never written it before, it took a lot of effort to write it out.
Mainly edit the article part, read and modify the keywords
Publish the article part
//定义JS的数组 var tagslist = []; //然后把用户输入的标签添加到这个数组里 tagslist.push("测试1"); //发送到后台的时候进行了编码,ECMAScript v3 反对使用escape,所以尽量不用了 encodeURI(tagslist)
//后台接收后,先用UrlDecode解码 //然后转换为数组 //然后使用implode以","为分割转为字符串存早数据库里 $arr = implode(',',array( UrlDecode( tagslist ) ) ); <pre class="brush:php;toolbar:false"><code>**修改文章,前台再读取的时候** ```javascript //先定义数组 var tagslist = []; </code>```php $value){//遍历新数组 echo "tagslist[$key]='$value';\n";//遍历时依次赋值给js的数组 } ?>
Then just operate the new js array.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert js array to php array. For more information, please follow other related articles on the PHP Chinese website!