I am trying to match values from a user's input ($index) to an existing array ($ppeWorn). A user can select more than one option. When I try to find out if there are keys of the user's input that match the $ppeWorn array, I get only the first item selected.
The value of dd($indexArray) is:
array:2 [
0 => "1"
1 => "2"
]
My code is as follows:
case 7:
$index = ($parts[6]) ;
$ppeWorn = [
'None',
'Gloves',
'Fabric mask',
'Surgical/Medical mask',
'N95 mask (or equivalent)',
'Face shield or goggles/protective glasses',
'Disposable gown',
'Waterproof apron',
];
$indexArray = explode(',', $index ) ;
dd($indexArray);
foreach($indexArray as $value) {
if ($ppeWorn[$value]) {
$session["ppes"] = $ppeWorn[$value];
$this->setSession($session);
dd($session);
$response = $this->sessionOpeningTag . "Have you received IPC training?\n1. Yes\n2. No";
} else {
$response = $this->sessionClosingTag . "You have entered an invalid answer";
$this->deleteSession($session);
}
}
break;