Pchp.Library.Arrays.array_merge C# (CSharp) Method

array_merge() public static method

Merges one or more arrays. Integer keys are changed to new ones, string keys are preserved. Values associated with existing string keys are be overwritten.
public static array_merge ( ) : PhpArray
return Pchp.Core.PhpArray
        public static PhpArray array_merge(params PhpArray[] arrays)
        {
            // "arrays" argument is PhpArray[] => compiler generates code converting any value to PhpArray.
            // Note, PHP does reject non-array arguments.

            if (arrays == null || arrays.Length == 0)
            {
                //PhpException.InvalidArgument("arrays", LibResources.GetString("arg:null_or_empty"));
                //return null;
                throw new ArgumentException();
            }

            var result = new PhpArray(arrays[0].Count);

            for (int i = 0; i < arrays.Length; i++)
            {
                if (arrays[i] != null)
                {
                    using (var enumerator = arrays[i].GetFastEnumerator())
                        while (enumerator.MoveNext())
                        {
                            if (enumerator.CurrentKey.IsString)
                                result[enumerator.CurrentKey] = enumerator.CurrentValue;
                            else
                                result.Add(enumerator.CurrentValue);
                        }
                }
            }

            // results is inplace deeply copied if returned to PHP code:
            //result.InplaceCopyOnReturn = true;
            return result;
        }