Home>Article>Backend Development> How to convert js array to php array

How to convert js array to php array

藏色散人
藏色散人 Original
2022-01-18 09:17:42 2918browse

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.

How to convert js array to php array

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 ) ) ); 
**修改文章,前台再读取的时候** ```javascript //先定义数组 var tagslist = []; 
```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!

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