3v4l.org

run code in 200+ 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.3.29, 5.4.26 - 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);
Output for 5.4.0 - 5.4.25
Parse error: syntax error, unexpected '$input' (T_VARIABLE) in /in/6R81p on line 2
Process exited with code 255.