3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getColors($item_colors, $result = []){ preg_match_all('/(\w+),|(\w+)\/(\w+)/', $item_colors, $colors); foreach ($colors as $key => $value) { if ($key === 0) continue; array_push($result, ...$value); } return array_filter($result); } $item_colors = "Vario Base Unit with steel, large, black/orange"; echo implode(' ', getColors($item_colors)); //steel large black orange var_dump(getColors($item_colors)); // array(4) { // [0]=> // string(5) "steel" // [1]=> // string(5) "large" // [5]=> // string(5) "black" // [8]=> // string(6) "orange" // }

preferences:
61.86 ms | 402 KiB | 5 Q