explode() 函数把字符串分割为数组;implode() 函数把数组元素组合为一个字符串。
explode
定义 array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] ) 参数: limit 限制结果的个数。
<?php
$str = "hi, jason, world";
print_r(explode(',', $str));
print_r(explode(',', $str, 2));
输出:
Array
(
[
0] => hi
[
1] => jason
[
2] => world
)
Array
(
[
0] => hi
[
1] => jason, world
)
implode
定义
string implode (
string $glue ,
array $pieces )
string implode (
array $pieces )
<?php
$array = array('hello', 'world', 'is', 'php');
echo implode(' ', $array);
echo "\n";
$array1 = array('a' => 'hello', 'b'=>'world', 'x' => 'jason' );
echo implode(' ', $array1);
输出
hello world
is php
hello world jason