<?php $pattern = '~^(?<animal>DOG|CAT)?(?<color>RED|BLUE)?$~i'; if ( preg_match($pattern, 'dog', $m) ) { $arr = ['animal' => '', 'color' => '']; print_r(array_intersect_key($m, $arr) + $arr); }
You have javascript disabled. You will not be able to edit any code.