I have the following script where I'm checking/matching items between two array. If 2nd array contains different item then return false;
$requiredString = [
"string1",
"string2",
"string3",
"string4",
"string5"
];
$receivedString = [
"string1",
"string2",
"string3",
"string4",
"testString7"
];
foreach ($receivedString as $key => $value) {
if (!in_array($value, $requiredString)) {
return false;
}
}
return true;
The script works good but I want to refactor the script. I.E make short or decrease execution time.
Is there a possible way to refactor the script ?