public static function testModel($returnType = 'array', $refresh = false, $autoset = true) { $cachekey = 'test-array-model'; if ($refresh) { BCacheHelper::delete($cachekey); } $data = self::get($cachekey, function () { $users = User::model()->findAll(array('condition' => 'isdelete=0', 'limit' => 10)); $users = BArrayHelper::getModelIndexArray($users, 'userid', BCacheHelper::getPreChar()); return $users; }, $autoset); return $data; }
/** * 分割字符串返回数组 * @author wjh 20141111 * @param $id * @return array * @throws CHttpException */ public static function getArrayFromString($id) { if (empty($id)) { return array(); } if (is_string($id)) { $idlist = explode(',', trim($id, ',')); } else { $idlist = BArrayHelper::removeEmpty($id); } return $idlist; }
/** * getAttributesArray * @param $data * @return array */ public static function print_r2($data) { if (BArrayHelper::isCActiveRecordArray($data)) { $data = self::getAttributesArray($data); } self::print_r($data); }
/** * 移除枚举中的元素 * @author wjh 2014-8-19 * @param $arr * @param $items * @return array */ public static function removeItems($arr, $items) { return BArrayHelper::array_remove_keys($arr, $items); }
/** * 获取类型定义中的 index 或 key * @author wjh 2014-6-3 * @param array $arr * @param string $text index or key * @return string */ public static function getKey($arr, $text) { $result = BArrayHelper::array_func($arr, function ($k, $v, $userdata) use($text) { return $k; }, function ($k, $v, $userdata) use($text) { return trim($v) == trim($text); }); return is_null($result) ? '' : implode(',', $result); }