Home  >  Q&A  >  body text

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

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

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

?>

阿神阿神2770 days ago683

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-10 16:15:38

    $result = array_splice( explode(',', $week), -2 );
    var_dump($result);

    reply
    0
  • PHPz

    PHPz2017-04-10 16:15:38

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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-10 16:15:38

    split(分割符):根据分割字符,把字符串拆分成数组

    reply
    0
  • Cancelreply