Home >Backend Development >PHP Tutorial >请问用哪个字符串函数截取下面字符串最后两项并转换为数组?

请问用哪个字符串函数截取下面字符串最后两项并转换为数组?

WBOY
WBOYOriginal
2016-06-06 20:25:481117browse

请问用哪个函数将下面的字符串截取后面两项并转换为数组?

$week = "Monday,Tuesday,Wednesay,Thursday,Friday,Saturday,Sunday";

?>

回复内容:

请问用哪个函数将下面的字符串截取后面两项并转换为数组?

$week = "Monday,Tuesday,Wednesay,Thursday,Friday,Saturday,Sunday";

?>

<code>$result = array_splice( explode(',', $week), -2 );
var_dump($result);</code>

先分割成数组 然后用array_splice取数组的后两个元素

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn