What is wrong with your initial approach is that you run a GroupOfEight loop twice . You have two for-loops.
First, you select each array in GroupOfEight, and in the second loop, you look at each value of the array.
If you want to use your original approach, get rid of the extra loop:
echo "Hello, World!"; $GroupOfEight = array ( array(0,1,3,2,4,5,7,6), array(4,5,6,7,16,12,13,14), array(12,13,15,14,8,9,11,10), array(2,6,14,10,3,7,15,11), array(1,3,5,7,13,15,9,11), array(0,4,12,8,1,5,13,9), array(0,1,3,2,8,9,11,10) ); $myStack = array(0,1,3,2,4,5,7,6); //Dynamic, gets value by POST method. for($i=0; $i<count($GroupOfEight);$i++) { $containsSearch = count(array_intersect($myStack,$GroupOfEight[$i])) == count($myStack); if($containsSearch===true) { echo "Woo! GroupOfEight[$i], <br/>" . print_r($GroupOfEight[$i], true) . "<br/>==<br/>" . print_r($myStack, true); } }
Demo: http://codepad.viper-7.com/0hRNHz
You can do the same with array_diff :
for($i=0; $i<count($GroupOfEight);$i++) { if(count(array_diff($myStack,$GroupOfEight[$i]))==0) { echo "Woo! GroupOfEight[$i], <br/>" . print_r($GroupOfEight[$i], true) . "<br/>==<br/>" . print_r($myStack, true); } }
Demo: http://codepad.viper-7.com/6uLd9L
Update
Associated SO record: Check if two array values ββare equal (ignoring order)