Is there a better way to combine these arrays? Is there a better way to do this kind of array combination with a PHP native function like array_combine?  I'm trying to improve my skills, and at certain points I note that I am using too many nested foreach for almost everything. 

Using PHP 5.4

   $array = Array(
      'GroupName' =&gt; 'Emilio',
      'Moduleid' =&gt; Array(
          0 =&gt; 15,
          1 =&gt; 12,
          2 =&gt; 9,
          3 =&gt; 1,
          4 =&gt; 11,
          5 =&gt; 10
      ),
      'Permission' =&gt; Array(
          15 =&gt; 'W',
          12 =&gt; 'R',
          14 =&gt; 'W',
          9 =&gt; 'W',
          1 =&gt; 'R',
          13 =&gt; 'W',
          11 =&gt; 'W',
          10 =&gt; 'R'
      )
  );


  foreach ($array['Moduleid'] as $value) {
    foreach ($array['Permission'] as $key1 =&gt; $value1) {
      if ($value == $key1) {
        $result[$key1] = $value1;
      }
    }
  }
  $newArray = array(
      'GroupName' =&gt; $array['GroupName'],
      'ModulePermission' =&gt; $result
  );
  unset($array);

  echo '&lt;pre&gt;';
  print_r($newArray);
  echo '&lt;/pre&gt;';


Output

Array
(
    [GroupName] =&gt; Emilio
    [ModulePermission] =&gt; Array
        (
            [15] =&gt; W
            [12] =&gt; R
            [9] =&gt; W
            [1] =&gt; R
            [11] =&gt; W
            [10] =&gt; R
        )

)
Using in_array can be droped one foreach

$result = array();
foreach ($array['Permission'] as $key =&gt; $value) {
  if (in_array($key, $array['Moduleid'])) {
     $result[$key] = $value;
  }
}