i try to add multiple elements to an array (in this case example1 and test1 to $allCats) but it still dont work :( can anyone explain me my mistake? or what i do wrong?
function getCats($Catlist, $name) {
$regex = '('.implode('|', $Catlist).')';
$success = preg_match_all($regex, $name, $matches);
return $success ? $matches[0] : [];
}
function Cats($name, $wrongCatlist, $allCats, $Catlist) {
$Cats = getCats($Catlist, $name);
$Cats2 = array_unique ( $Cats );
$Cats3 = '"'.implode('", "', $Cats2).'"';
array_push($allCats, $Cats3);
}
$name = "adidas example1 handschuhe test1 nike";
$wrongCatlist = [
];
global $allCats;
$allCats = [
];
$Catlist = [
"example1",
"test1"
];
Cats($name, $wrongCatlist, $allCats, $Catlist);
$allCats2 = ''.implode(', ', $allCats).'';
echo $allCats2;