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

array_multisort() public static method

Sort multiple arrays.
Reindexes integer keys in the sorted arrays and restarts their intrinsic enumerators.
is a null reference (Warning). Arrays has different lengths (Warning). Invalid sorting flags (Warning). Multiple sorting flags applied on single array (Warning).
public static array_multisort ( Context ctx, [ first ) : bool
ctx Pchp.Core.Context Current runtime context.
first [ The first array to be sorted.
return bool
        public static bool array_multisort(Context ctx, [In, Out] PhpArray first, params PhpValue[] args)
        {
            // some "args" are also [PhpRw] but which ones is compile time unknown
            // but it is not neccessary to mark them since this attribute has no important effect

            if (first == null)
            {
                //TODO: PhpException.ArgumentNull("first");
                throw new ArgumentNullException();
            }

            IComparer<KeyValuePair<IntStringKey, PhpValue>>[] comparers;
            PhpArray[] arrays;
            int length = MultiSortResolveArgs(ctx, first, args, null, null);

            if (length == 0)
            {
                return false;
            }
            if (length == 1)
            {
                comparers = new IComparer<KeyValuePair<IntStringKey, PhpValue>>[1];
                MultiSortResolveArgs(ctx, first, args, null, comparers);
                first.Sort(comparers[0]);
                first.ReindexIntegers(0);
                first.RestartIntrinsicEnumerator();
                return true;
            }

            arrays = new PhpArray[length];
            comparers = new IComparer<KeyValuePair<IntStringKey, PhpValue>>[length];
            MultiSortResolveArgs(ctx, first, args, arrays, comparers);
            PhpHashtable.Sort(arrays, comparers);

            for (int i = 0; i < length; i++)
            {
                arrays[i].ReindexIntegers(0);
                arrays[i].RestartIntrinsicEnumerator();
            }

            return true;
        }