3v4l.org

run code in 300+ PHP versions simultaneously
<?php $csv_specie = array("Mouse","Human"); $CDNA = 'Human interleukin 2 (IL2)a;Ampicillin resistance gene (amp)a;Mouse amp gene;Some other stuff unknown to man kind;some other human stuff'; $cdna = explode(";", $CDNA); Foreach($csv_specie as $specie){ $matches[$specie] = preg_grep("/\b" . $specie . "\b/i", $cdna); Echo $specie . " - " . implode("\n" . $specie . " - " , $matches[$specie]) . "\n"; // Remove matched items from $cdna $cdna = array_diff($cdna, $matches[$specie]); } // What is left in $cdna is not matched $matches["N/A"] = $cdna; Echo "\nN/A - " . implode("\nN/A - ", $matches["N/A"]); Echo "\n\n"; Var_dump($matches);

preferences:
163.75 ms | 408 KiB | 5 Q