AddValue() public method

public AddValue ( PhpValue value ) : void
value PhpValue
return void
コード例 #1
0
ファイル: DateTimeFunctions.cs プロジェクト: iolevel/peachpie
        internal static PhpArray GetLocalTime(TimeZoneInfo currentTz, System_DateTime utc, bool returnAssociative)
        {
            PhpArray result;

            var local = TimeZoneInfo.ConvertTime(utc, currentTz);

            if (returnAssociative)
            {
                result = new PhpArray(0, 9);
                result["tm_sec"] = PhpValue.Create(local.Second);
                result["tm_min"] = PhpValue.Create(local.Minute);
                result["tm_hour"] = PhpValue.Create(local.Hour);
                result["tm_mday"] = PhpValue.Create(local.Day);
                result["tm_mon"] = PhpValue.Create(local.Month - 1);
                result["tm_year"] = PhpValue.Create(local.Year - 1900);
                result["tm_wday"] = PhpValue.Create((int)local.DayOfWeek);
                result["tm_yday"] = PhpValue.Create(local.DayOfYear - 1);
                result["tm_isdst"] = PhpValue.Create(currentTz.IsDaylightSavingTime(local) ? 1 : 0);
            }
            else
            {
                result = new PhpArray(9, 0);
                result.AddValue(PhpValue.Create(local.Second));
                result.AddValue(PhpValue.Create(local.Minute));
                result.AddValue(PhpValue.Create(local.Hour));
                result.AddValue(PhpValue.Create(local.Day));
                result.AddValue(PhpValue.Create(local.Month - 1));
                result.AddValue(PhpValue.Create(local.Year - 1900));
                result.AddValue(PhpValue.Create((int)local.DayOfWeek));
                result.AddValue(PhpValue.Create(local.DayOfYear - 1));
                result.AddValue(PhpValue.Create(currentTz.IsDaylightSavingTime(local) ? 1 : 0));
            }

            return result;
        }
コード例 #2
0
ファイル: Arrays.cs プロジェクト: iolevel/peachpie
        /// <summary>
        /// Retrieves an array of some keys contained in a given array.
        /// </summary>
        /// <param name="array">An array which keys to get.</param>
        /// <param name="searchValue">Only the keys for this value are returned. 
        /// Values are compared using regular comparison method (<see cref="PhpComparer.CompareEq"/>).</param>
        /// <param name="strict">If true, uses strict comparison method (operator "===").</param>
        /// <returns>An array of keys being associated with specified value. 
        /// Keys in returned array are successive integers starting from zero.</returns>
        /// <exception cref="PhpException"><paramref name="array"/> is a <B>null</B> reference.</exception>
        public static PhpArray array_keys(PhpArray array, PhpValue searchValue, bool strict = false)
        {
            if (array == null)
            {
                //PhpException.ArgumentNull("array");
                //return null;
                throw new ArgumentNullException();
            }

            var result = new PhpArray();
            var enumerator = array.GetFastEnumerator();

            if (strict)
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.CurrentValue.StrictEquals(searchValue))
                        result.AddValue(PhpValue.Create(enumerator.CurrentKey));
                }
            }
            else
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.CurrentValue.Equals(searchValue))
                        result.AddValue(PhpValue.Create(enumerator.CurrentKey));
                }
            }

            // no need to make a deep copy since keys are immutable objects (strings, ints):
            return result;
        }