php数组与字符串之间的转换
我们在实际使用PHP进行字符串和数组之间进行转换时,implode和explode两个函数将会比较有用。implode() 函数进行PHP数组转字符串,explode() 函数则是用来实现PHP字符串转数组的。
一、PHP数组转字符串 implode()
1<?php
2$vegetables[0] = "corn";
3$vegetables[1] = "broccoli";
4$vegetables[2] = "zucchini";
5$text = implode(",", $vegetables);
6echo $text;
7?>
运行结果为:corn,broccoli,zucchini
二、PHP字符串转数组 explode()
1<?php
2$text = "corn, broccoli, zucchini";
3$vegetables = explode(", ", $text);
4print_r($vegetables);
5?>
6其运行结果为:
7Array
8(
9[0] => corn
10[1] => broccoli
11[2] => zucchini
12)
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/php-implode-explode/2989.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.