public static PhpArray Values(PhpArray array) { if (array == null) { PhpException.ArgumentNull("array"); return null; } // references are not dereferenced: PhpArray result = new PhpArray(array.Count); using (var enumerator = array.GetFastEnumerator()) while (enumerator.MoveNext()) result.AddToEnd(enumerator.CurrentValue); // result is inplace deeply copied on return to PHP code: result.InplaceCopyOnReturn = true; return result; }
public static PhpArray Keys(PhpArray array, object searchValue, bool strict) { if (array == null) { PhpException.ArgumentNull("array"); return null; } PhpArray result = new PhpArray(); if (!strict) { using (var enumerator = array.GetFastEnumerator()) while (enumerator.MoveNext()) { if (PhpComparer.CompareEq(enumerator.CurrentValue, searchValue)) result.AddToEnd(enumerator.CurrentKey.Object); } } else { using (var enumerator = array.GetFastEnumerator()) while (enumerator.MoveNext()) { if (Operators.StrictEquality(enumerator.CurrentValue, searchValue)) result.AddToEnd(enumerator.CurrentKey.Object); } } // no need to make a deep copy since keys are immutable objects (strings, ints): return result; }
public static PhpArray Keys(PhpArray array) { if (array == null) { PhpException.ArgumentNull("array"); return null; } // no need to make a deep copy since keys are immutable objects (strings, ints): var result = new PhpArray(array.Count); using (var enumerator = array.GetFastEnumerator()) while (enumerator.MoveNext()) result.AddToEnd(enumerator.CurrentKey.Object); return result; }
public object fetchAll(ScriptContext context, [Optional]object fetch_style/*=null*/, [Optional]object fetch_argument/*=null*/, [Optional]object ctor_args/*=null*/) { PhpArray arr = new PhpArray(); PDOFetchType fetch; if (fetch_style == null || fetch_style == Arg.Default) fetch = PDOFetchType.PDO_FETCH_BOTH; else fetch = (PDOFetchType)(int)fetch_style; // TODO: fetch bitwise combinations (group, unique, ...) if (fetch == PDOFetchType.PDO_FETCH_COLUMN) { int column = (fetch_argument == null || fetch_argument == Arg.Default) ? 0 : Core.Convert.ObjectToInteger(fetch_argument); while (true) { var ret = this.fetch(context, (int)PDOFetchType.PDO_FETCH_NUM) as PhpArray; if (ret == null) break; arr.AddToEnd(ret[column]); } } else { while (true) { object ret = this.fetch(context, (int)fetch); if ((ret is bool && ((bool)ret) == false) || ret == null) { break; } else { arr.AddToEnd(ret); } } } return arr; }
public static PhpArray FetchAll(PhpResource resultIdentifier, object result_type, object decode_binary) { PhpSQLiteDbResult res = PhpSQLiteDbResult.ValidResult(resultIdentifier); if (res == null) { return null; } SQLite.QueryResultKeys resType = QueryResultKeys.Both; if (result_type != null) { int val = PHP.Core.Convert.ObjectToInteger(result_type); if (val != 0) { resType = (SQLite.QueryResultKeys)val; } } bool intKey = (resType & SQLite.QueryResultKeys.Numbers) == SQLite.QueryResultKeys.Numbers; bool strKey = (resType & SQLite.QueryResultKeys.ColumnNames) == SQLite.QueryResultKeys.ColumnNames; PhpArray arr = new PhpArray(); PhpArray line = null; while ((line = res.FetchArray(intKey, strKey)) != null) { arr.AddToEnd(line); } if (arr.Count == 0) { return null; } return arr; }
public object fetchAll(ScriptContext context, object fetch_style, object fetch_argument, object ctor_args) { PhpArray arr = new PhpArray(); PDOFetchType fetch; if (fetch_style == null) { fetch = PDOFetchType.PDO_FETCH_BOTH; } else { fetch = (PDOFetchType)fetch_style; } while (true) { switch (fetch) { case PDOFetchType.PDO_FETCH_BOTH: case PDOFetchType.PDO_FETCH_ASSOC: case PDOFetchType.PDO_FETCH_NUM: break; default: throw new NotImplementedException(); } object ret = this.fetch(context, fetch); if ((ret is bool && ((bool)ret) == false) || ret == null) { break; } else { arr.AddToEnd(ret); } } return arr; }