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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 English version
Recommended: Win version, supports code prompts!
