Exemplo n.º 1
0
Variant f_array_column(CVarRef input, CVarRef val_key,
                       CVarRef idx_key /* = null_variant */) {
  /* Be strict about array type */
  getCheckedArrayRet(input, uninit_null());
  Variant val = val_key, idx = idx_key;
  if (!array_column_coerce_key(val, "column") ||
      !array_column_coerce_key(idx, "index")) {
    return false;
  }
  Array ret = Array::Create();
  for(auto it = arr_input.begin(); !it.end(); it.next()) {
    if (!it.second().isArray()) {
      continue;
    }
    Array sub = it.second().toArray();

    Variant elem;
    if (val.isNull()) {
      elem = sub;
    } else if (sub.exists(val)) {
      elem = sub[val];
    } else {
      // skip subarray without named element
      continue;
    }

    if (idx.isNull() || !sub.exists(idx)) {
      ret.append(elem);
    } else if (sub[idx].isObject()) {
      ret.set(sub[idx].toString(), elem);
    } else {
      ret.set(sub[idx], elem);
    }
  }
  return ret;
}
Exemplo n.º 2
0
bool f_in_array(CVarRef needle, CVarRef haystack, bool strict /* = false */) {
  getCheckedArrayRet(haystack, false);
  return arr_haystack.valueExists(needle, strict);
}
Exemplo n.º 3
0
Variant f_array_search(CVarRef needle, CVarRef haystack,
                       bool strict /* = false */) {
  getCheckedArrayRet(haystack, false);
  return arr_haystack.key(needle, strict);
}
Exemplo n.º 4
0
Variant f_array_flip(CVarRef trans) {
  getCheckedArrayRet(trans, false);
  return ArrayUtil::Flip(arr_trans);
}