php explode 函数使用详细理解

 
 
 



function dump($str=''){
echo '
'; 
  
var_dump($str);
exit;
};
//explode()函数


//explode(separator,string,limit)
//separator:分割标志符
//string:被分割的字符串
//limit :分割后返回的元素数目

$str = 'one,two,three,four';

print_r(explode(',' , $str));


// 零 limit
print_r(explode(',',$str,0));


// 正的 limit  分成两组
print_r(explode(',',$str,2));


// 负的 limit  除了最后两组
print_r(explode(',',$str,-2));

//运行结果如下:
Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
Array
(
[0] => one,two,three,four
)
Array
(
[0] => one
[1] => two,three,four
)
Array
(
[0] => one
[1] => two
)




?> 

 

你可能感兴趣的:(PHP网站)