3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str ="(10*2)/(3*40)*100"; $str = str_split($str); // make str an array $arr = array(); $j=0; // counter for new array for($i=0;$i<count($str);$i++){ if(is_numeric($str[$i])){ // if the item is a number $arr[$j] = $str[$i]; // add it to new array $k = $i+1; while(is_numeric($str[$k])){ // while it's still a number append to new array item. $arr[$j] .= $str[$k]; $k++; // add one to counter. if($k == count($str)) break; // if counter is out of bounds, break loop. } $j++; // we are done with this item, add one to counter. $i=$k-1; // set new value to $i }else{ // not number, add it to the new array and add one to array counter. $arr[$j] = $str[$i]; $j++; } } var_dump($arr);

preferences:
153.09 ms | 406 KiB | 5 Q