- array_push: documentation ( source)
- var_dump: documentation ( source)
- preg_match_all: documentation ( source)
- implode: documentation ( source)
- array_filter: documentation ( source)
<?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"
// }