if ( count($value) >= 3 ) {
echo '<pre>'.print_r( array_slice($value, 0, -1) ,1).'</pre>';
echo '<pre>'.print_r( array_slice($value, -1) ,1).'</pre>';
}
...它打印出我期望的值,但我不知道如何将其转换为字符串,例如:
Array
(
[0] => Dr.
[1] => John
[2] => Appleseed
)
Array
(
[0] => Jr
)
变为:
Array
(
[0] => Dr. John Appleseed
)
Array
(
[0] => Jr
)
答案 0 :(得分:1)
您可以使用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) ""
?>
特定代码
<?php
echo '<pre>' . implode($value) . '</pre>'; // Dr. John Appleseed
echo '<pre>' . $value[0] . '</pre>'; // Jr