You are here

function httprl_recursive_array_reference_extract in HTTP Parallel Request & Threading Library 6

Same name and namespace in other branches
  1. 7 httprl.module \httprl_recursive_array_reference_extract()

Replace data in place so pass by reference sill works.

Parameters

array $array: An array containing the references if any.

array $data: An array that has the new values to copy into $array.

int $depth: Only go 10 levels deep. Prevent infinite loops.

1 call to httprl_recursive_array_reference_extract()
httprl_extract_background_callback_data in ./httprl.module
Extract background callback data.

File

./httprl.module, line 2141
HTTP Parallel Request Library module.

Code

function httprl_recursive_array_reference_extract(&$array, $data, $depth = 0) {
  $depth++;
  foreach ($array as $key => &$value) {
    if (isset($data[$key])) {
      if (is_array($data[$key]) && is_array($value) && $depth < 10) {
        $value = httprl_recursive_array_reference_extract($value, $data[$key], $depth);
      }
      else {
        $value = $data[$key];
      }
    }
    else {
      $value = NULL;
    }
  }

  // Copy new keys into the data structure.
  foreach ($data as $key => $value) {
    if (isset($array[$key])) {
      continue;
    }
    $array[$key] = $value;
  }
}