Home  >  Article  >  php教程  >  String splitting, when encountering an interval, iterate through all values ​​in the interval

String splitting, when encountering an interval, iterate through all values ​​in the interval

不言
不言Original
2018-05-19 16:42:131760browse

Jump to                                                                                                     [Full screen preview]

public function explodes($str){

    $return = [];

    $array = [];

    foreach(explode(",",$str) as $k => $v){

        $return = array_merge($return,(strpos($v,'-') && $array = explode('-',$v))?range($array[0],$array[1]):[$k=>intval($v)]);

    }

    return $return;

}

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
Previous article:stu student managementNext article:stu student management