Home > php教程 > 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

不言
Release: 2018-05-19 16:42:13
Original
1835 people have browsed it

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;

}
Copy after login

Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template