- 相關(guān)推薦
php字符串與數(shù)組怎么轉(zhuǎn)換
在php中我們要把字符串轉(zhuǎn)換在數(shù)組里使用可以函數(shù)的辦法,具體情況如下,更多消息請關(guān)注應(yīng)屆畢業(yè)生網(wǎng)!
在php中我們要把字符串轉(zhuǎn)換在數(shù)組可使用函數(shù)有str_split()、explode(),preg_split()函數(shù)了,如果把數(shù)組轉(zhuǎn)換在字符串我們也有一個函數(shù)implode()函數(shù)與直接把數(shù)組連接起來。
我們先來看字符串轉(zhuǎn)換成數(shù)組
str_split()
print_r(str_split("Hello"));
?>
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
)
explode()
$str = "Hello world. It's a beautiful day.";print_r (explode(" ",$str));?>
結(jié)果
Array
(
[0] => Hello
[1] => world.
[2] => It's
[3] => a
[4] => beautiful
[5] => day.
)
preg_split()函數(shù)
代碼如下
$user_info = "+J+++G+++++w";
$fields = preg_split("/+{1,}/", $user_info);while ($x < sizeof($fields)) :
print $fields[$x]. "
";
$x++;
endwhile;
?>
總結(jié)在php中str_split()、explode()函數(shù)功能是一樣的,這里就不介紹了。
把數(shù)組轉(zhuǎn)換在字符串
implode()
例
代碼如下
$array = array('a','b','c');
echo implode($array);
//結(jié)果 abc
【php字符串與數(shù)組怎么轉(zhuǎn)換】相關(guān)文章:
PHP 數(shù)組和字符串互相轉(zhuǎn)換實現(xiàn)方法12-02
PHP數(shù)組函數(shù)知識11-29
php數(shù)組長度的方法03-03
PHP數(shù)組長度的技巧03-28
php字符串截取問題11-17
php字符串截取函數(shù)03-21
php的字符串常用函數(shù)11-27
php遞歸遍歷多維數(shù)組的方法03-02