3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $input = '100,100-200, 300, 320, 400-200'; $params = explode(',', $input); $ranges = array(); foreach ($params as $param) { $param = trim($param); if (strpos($param, '-') !== FALSE) { $range = explode('-', $param); } else { $range = array($param, $param); } $ranges[] = $range; } foreach ($ranges as $range) { print 'from: '. $range[0]. ' to: '. $range[1] . "\n"; }
based on 7TEiu
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
from: 100 to: 100 from: 100 to: 200 from: 300 to: 300 from: 320 to: 320 from: 400 to: 200