区间计算 给定值 $str="11-13,17,18,22-25"; 结果打印 11,12,17,18,22,23,24,25 1. [代码] [PHP]代码 public function explodes($str){ $return = []; $array = []; foreach(explode(",",$str) as $k = $v){ $return = array_merge($return,(s
给定值
$str="11-13,17,18,22-25";
结果打印
11,12,17,18,22,23,24,25
1. [代码][PHP]代码
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; }