Checkout the following code. It gives you all the permutations that you require.
<?php
//$arr = array(
// array('a', 'b', 'c', 'd'),
// array('e', 'f', 'g', 'h'),
// array('p', 'q', 'r', 's')
//);
$arr = array(
array('n', 'q'),
array('d', 'g')
);
$permutations = $arr[0];
for ($i = 1; $i < count($arr); $i++)
{
$inner_temp = array();
for ($k = 0; $k < count($permutations); $k++)
{
for ($j = 0; $j < count($arr[$i]); $j++)
array_push($inner_temp, $permutations[$k] . $arr[$i][$j]);
}
$permutations = $inner_temp;
}
echo "<pre>";
print_r($permutations);
?>