3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '___RN___RN___R___N___RN___RN'; $del = array('RN', 'R', 'N'); # This won't work if delimiters 2-n include characters from delimiter 1 var_dump(explode( $del[0], str_replace($del, $del[0], $str))); # This, however, will work function array_explode($delimiters, $string){ if(!is_array(($delimiters)) && !is_array($string)){ //if neither the delimiter nor the string are arrays return explode($delimiters,$string); } else if(!is_array($delimiters) && is_array($string)) { //if the delimiter is not an array but the string is foreach($string as $item){ foreach(explode($delimiters, $item) as $sub_item){ $items[] = $sub_item; } } return $items; } else if(is_array($delimiters) && !is_array($string)) { //if the delimiter is an array but the string is not $string_array[] = $string; foreach($delimiters as $delimiter){ $string_array = array_explode($delimiter, $string_array); } return $string_array; } } var_dump(array_explode($del,$str));

preferences:
40.72 ms | 406 KiB | 5 Q