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

array_product() public static method

Computes a product of all values in an array. Each value is converted to a number in the same way it is done by PHP.
Thrown if the argument is null.
public static array_product ( PhpArray array ) : PhpNumber
array Pchp.Core.PhpArray
return PhpNumber
        public static PhpNumber array_product(PhpArray array)
        {
            if (array == null)
            {
                //PhpException.ArgumentNull("array");
                //return 0;
                throw new ArgumentNullException(nameof(array));
            }

            if (array.Count == 0)
            {
                return PhpNumber.Default;
            }

            PhpNumber result = PhpNumber.Create(1L);
            PhpNumber num;

            var iterator = array.GetFastEnumerator();
            while (iterator.MoveNext())
            {
                iterator.CurrentValue.ToNumber(out num);

                result *= num;
            }

            //
            return result;
        }