Example: if i have two array saved in database in different records $array1 = [1,2,3,4,5,6]; $array2 = [6,5,4,3,2,1];
and subArray $subArray = [1,2,3];
and i want to get the array where the sequence of $subArray exists using query in laravel which will $array1
CodePudding user response:
Here is a possible solution:
function isSequence($array, $subArray){
$keys = array_keys($array, $subArray[array_keys($subArray)[0]]);
foreach($keys as $key) {
if(array_slice($array, $key, count($subArray)) == $subArray){
return true;
}
}
return false;
}