Function AClone() Foundation

Creates a complete copy of a single or multi-dimensional array().

Syntax
AClone( <aArray> ) --> aClonedArray
Parameters
<aArray>
<aArray> is the array which is completely copied.
Return

The return value of AClone() is a duplicate of <aArray>.

Description

The array function AClone() is used to create copies of multi-dimensional arrays. Since the function ACopy() only copies the elements in the first dimension of an array and does not consider subarrays, it cannot be used to copy a multi-dimensional array. AClone(), on the other hand, also creates copies of subarrays if array references are contained in the elements of <aArray>.

Examples
Comparison between ACopy() and AClone()

// In the example, an array is created which contains a subarray 
// in its second element. A copy of the array is then made 
// using ACopy() and AClone(). When copied using ACopy(), 
// the second element of both the original array and the copy 
// reference the same array. The copy made with AClone(), however, 
// contains a duplicate array as the second element. 

PROCEDURE Main 
   LOCAL aArray , aClone, aCopy 

   aArray := {"A", ; 
             {"B1","B2","B3"}, ;       // subarray in second element 
              "C", ; 
              "D" } 

   aClone := AClone( aArray )          // create complete copy 

   aCopy  := ACopy( aArray, Array(4) ) // only first dimension 
                                       // is copied 

   ? aCopy [2][1] := "Xbase++"         // result: Xbase++ 
   ? aClone[2][1]                      // result: B1 
   ? aArray[2][1]                      // result: Xbase++ 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.