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;
}