function printPermutationRows($matrix, $givenrow) {
$rows = count($matrix);
$cols = count($matrix[0]);
$Set = array();
// array_unshift() prepends passed elements to the front of the array
for ($j = 0; $j < $cols; $j++) {
(!in_array($matrix[$givenrow][$j], $Set) ? array_unshift($Set,$matrix[$givenrow][$j]) : 0);
}
for ($i = 0; $i < $rows; $i++) {
if ($i == $givenrow) {
continue;
}
$j = 0;
for (; $j < $cols; $j++) {
if (!in_array($matrix[$i][$j], $Set)) {
break;
}
}
if ($j != $cols) {
continue;
}
echo $i . ", ";
}
}
$givenrow = 1;
$matrix = array(
array(7, 9, 4, 3, 1),
array(4, 7, 9, 1, 3),
array(4, 7, 8, 1, 2),
array(1, 6, 9, 7, 4),
array(9, 1, 3, 7, 4)
);
printPermutationRows($matrix, $givenrow);
/*
run:
0, 4,
*/