$array=explode(separator,$string);
$string=implode(glue,$array);
把字符串打散为数组: 例子里面的【" "】这部分为分割的字符
<?php $str = "Hello world. I love Shanghai!"; print_r (explode(" ",$str)); ?> Array ( [0] => Hello [1] => world. [2] => I [3] => love [4] => Shanghai! )
把数组元素组合为字符串:
<?php $arr = array(‘Hello‘,‘World!‘,‘I‘,‘love‘,‘Shanghai!‘); echo implode(" ",$arr); ?> Hello World! I love Shanghai!
时间: 2024-10-14 15:08:38