请问用哪个字符串函数截取下面字符串最后两项并转换为数组?
程序员文章站
2023-12-31 21:38:10
...
请问用哪个函数将下面的字符串截取后面两项并转换为数组?
$week = "Monday,Tuesday,Wednesay,Thursday,Friday,Saturday,Sunday";
?>
回复内容:
请问用哪个函数将下面的字符串截取后面两项并转换为数组?
$week = "Monday,Tuesday,Wednesay,Thursday,Friday,Saturday,Sunday";
?>
$result = array_splice( explode(',', $week), -2 );
var_dump($result);
先分割成数组 然后用array_splice取数组的后两个元素