3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?javascript $input = '1, 4, 7, 20-25, 31, 46, 100'; $entries = array_map( 'trim', str_getcsv( $input)); $result = array(); foreach( $entries as $entry) { if( strpos( $entry, '-') !== false) { list( $start, $end) = explode( '-', $entry); $result = array_merge( $result, range( $start, $end)); } else { $result[] = $entry; } } print_r( $result);
Output for 5.3.0 - 5.4.32
<?javascript $input = '1, 4, 7, 20-25, 31, 46, 100'; $entries = array_map( 'trim', str_getcsv( $input)); $result = array(); foreach( $entries as $entry) { if( strpos( $entry, '-') !== false) { list( $start, $end) = explode( '-', $entry); $result = array_merge( $result, range( $start, $end)); } else { $result[] = $entry; } } print_r( $result);