/// <summary> /// Removes the first item of an array and reindex integer keys starting from zero. /// </summary> /// <param name="array">The array to be shifted.</param> /// <returns>The removed object.</returns> /// <remarks>Resets intrinsic enumerator.</remarks> public static PhpValue array_shift(PhpArray array) { if (array == null) { //PhpException.ReferenceNull("array"); //return null; throw new ArgumentNullException(); } if (array.Count == 0) return PhpValue.Null; // dereferences result since the array doesn't do so: var result = array.RemoveFirst().Value; // TODO: PhpVariable.Dereference // reindexes integer keys starting from zero: array.ReindexIntegers(0); array.RestartIntrinsicEnumerator(); return result; }
/// <summary> /// Removes the last item from an array and returns it. /// </summary> /// <param name="array">The array whcih item to pop.</param> /// <returns>The last item of <paramref name="array"/> or a <b>null</b> reference if it is empty.</returns> /// <remarks>Resets intrinsic enumerator.</remarks> public static PhpValue array_pop(PhpArray array) { if (array == null) { //PhpException.ReferenceNull("array"); //return null; throw new ArgumentNullException(); } if (array.Count == 0) return PhpValue.Null; // dereferences result since the array doesn't do so: var result = (array.RemoveLast().Value); // TODO: PhpVariable.Dereference array.RefreshMaxIntegerKey(); array.RestartIntrinsicEnumerator(); return result; }