original_string: public static function reduceToElementsWithKey($array, $key) {
  
          if ($array instanceof AssociativeArray) {
              $array = $array->toArray();
          }
  
          $targetArray = array();
  
          foreach ($array as $itemKey => $value) {
  
              if ($itemKey == $key) {
                  $targetArray[$key] = $value;
              } else if (is_array($value) || $value instanceof AssociativeArray) {
                  $subArray = ArrayUtils::reduceToElementsWithKey($value, $key);
                  if (sizeof($subArray) > 0) {
                      $targetArray[$itemKey] = $subArray;
                  }
              }
  
          }
  
          return $targetArray;
  
      }
code: public static function reduceToElementsWithKey($array, $key) {
  
          if ($array instanceof AssociativeArray) {
              $array = $array->toArray();
          }
  
          $targetArray = array();
  
          foreach ($array as $itemKey => $value) {
  
              if ($itemKey == $key) {
                  $targetArray[$key] = $value;
              } else if (is_array($value) || $value instanceof AssociativeArray) {
                  $subArray = ArrayUtils::reduceToElementsWithKey($value, $key);
                  if (sizeof($subArray) > 0) {
                      $targetArray[$itemKey] = $subArray;
                  }
              }
  
          }
  
          return $targetArray;
  
      }
code_tokens: public static function reduceToElementsWithKey ( $ array , $ key ) { if ( $ array instanceof AssociativeArray ) { $ array = $ array -> toArray ( ) ; } $ targetArray = array ( ) ; foreach ( $ array as $ itemKey => $ value ) { if ( $ itemKey == $ key ) { $ targetArray [ $ key ] = $ value ; } else if ( is_array ( $ value ) || $ value instanceof AssociativeArray ) { $ subArray = ArrayUtils :: reduceToElementsWithKey ( $ value , $ key ) ; if ( sizeof ( $ subArray ) > 0 ) { $ targetArray [ $ itemKey ] = $ subArray ; } } } return $ targetArray ; }
docstring: Reduce the array to only elements with the passed key at any depth.
  
  @param $array
  @param $key
docstring_tokens: Reduce the array to only elements with the passed key at any depth .