Function to combine arrays of associative arrays
I know that the question is already answered with cFreed answer but I want show another approach.

While I was finding if there are some function that do that I found this on php.net

function array_merge_recursive_distinct ( array &amp;$array1, array &amp;$array2 )
{
  $merged = $array1;

  foreach ( $array2 as $key =&gt; &amp;$value )
  {
    if ( is_array ( $value ) &amp;&amp; isset ( $merged [$key] ) &amp;&amp; is_array ( $merged [$key] ) )
    {
      $merged [$key] = array_merge_recursive_distinct ( $merged [$key], $value );
    }
    else
    {
      $merged [$key] = $value;
    }
  }

  return $merged;
}


basically is the same that you want but only for two args so...
I tried to do this
pick args and send to that function in pairs

so, I write this. I tried to keep the soul of your code intact so you will see  $asObject = (T_OBJECT_CAST == $args[count($args)-1]);  and also     if($asObject) array_pop($args);

function array_merge_recursive_unique_keys(){
    $args     = func_get_args();
    $asObject = (T_OBJECT_CAST == $args[count($args)-1]);
    if($asObject) array_pop($args);

    $ret = $args;

    if(count($args)&gt;0){
        $partial = current($args);

        for($i = 1; $i&lt; count($args); $i++){
            if(is_array($args[$i]) &amp;&amp; is_array($partial)){
                $partial = array_merge_recursive_distinct($partial, $args[$i]);
            }           
        }

        if($asObject) {
            $ret = json_decode (json_encode ($partial), FALSE);
        }else{
            $ret = $partial;
        }

    }

    return $ret;
}