<?php $haystack = [0,0,0,1,1,0,1,1,0,0,1,1,0,0,1]; $needle = [1,1,0]; $needleCount = count($needle); $result = []; foreach ($haystack as $i => $straw) { $start = $i - $needleCount; if ( $start >= 0 && $needle === array_slice($haystack, $start, $needleCount) ) { $result[] = $straw; } } var_export($result);
You have javascript disabled. You will not be able to edit any code.