How to convert js array to php array

藏色散人
Release: 2023-03-14 20:32:01
Original
3026 people have browsed it

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)
Copy after login
//后台接收后,先用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的数组 } ?>
Copy after login

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!

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