PHP数组转字符串与PHP字符串转数组的相关方法解析
我们今天为大家介绍的PHP数组转字符串与PHP字符串转数组的代码将会用到函数implode() 和函数explode() 。其中implode() 函数是用来数组转字符串时用,而explode() 函数则是用来处理字符串转数组的。
PHP数组转字符串 implode()<?php $vegetables[0] = "corn"; $vegetables[1] = "broccoli"; $vegetables[2] = "zucchini"; $text = implode(",", $vegetables); echo $text; ?>
运行结果
corn,broccoli,zucchini
2 PHP字符串转数组 explode()
<?php $text = "corn, broccoli, zucchini"; $vegetables = explode(", ", $text); print_r($vegetables); ?>
运行结果:
相关推荐
songshijiazuaa 2020-09-01
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23