3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myString = "type:blue, type:red, shift:second, shift:first, category:circle, system:unknown"; $possibleKeys = [ "category", "shift", "type" ]; Foreach($possibleKeys as $key){ preg_match_all("/" . $key . ":(.*?),/", $myString, $m); $new[$key] = $m[1]; } Var_dump($new);

preferences:
35.71 ms | 405 KiB | 5 Q