implode 使用乙個字串將陣列變成字串
<?php
$array
=
array
(
'lastname'
,
'email'
,
'phone'
);
$comma_separated
= implode(
","
,
$array
); //使用 ,連線
echo
$comma_separated
;
// lastname,email,phone
// empty string when using an empty array:
var_dump(implode(
'hello'
,
array
()));
// string(0) ""
?>
explode 使乙個字串分割另乙個字串,返回乙個陣列
<?php
// 示例 1
$pizza
=
"piece1 piece2 piece3 piece4 piece5 piece6"
;
$pieces
=
explode
(
" "
,
$pizza
); 通過空格進行分割
echo
$pieces
[0];
// piece1
echo
$pieces
[1];
// piece2
// 示例 2
$data
=
"foo:*:1023:1000::/home/foo:/bin/sh"
;
list(
$user
,
$pass
,
$uid
,
$gid
,
$gecos
,
$home
,
$shell
) =
explode
(
":"
,
$data
);
echo
$user
;
// foo
echo
$pass
;
// *
?>
PHP 陣列轉字串,與字串轉陣列
php 陣列轉字串,與字串轉陣列 implode 使用乙個字串將陣列變成字串 array array lastname email phone comma separated implode array echo comma separated lastname,email,phone empty ...
PHP 陣列轉字串,與字串轉陣列
1 implode 使用乙個字串將陣列變成字串12 3456 78910 11 array array lastname email phone comma separated implode array echo comma separated lastname,email,phone empty...
php字串轉陣列函式,php字串轉陣列
php字串轉陣列 str split php 5,php 7 str split 將字串轉換為陣列 說明str split string string int split length 1 array 將乙個字串轉換為陣列。引數string 輸入字串。split length 每一段的長度。返回值如...