本文整理汇总了PHP中obj_to_array函数的典型用法代码示例。如果您正苦于以下问题:PHP obj_to_array函数的具体用法?PHP obj_to_array怎么用?PHP obj_to_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了obj_to_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
public function handle($data)
{
$this->validate_request(["assessment" => ["profile", "questions"]]);
$assessment = $data->{"assessment"};
$profileJson = $assessment->{"profile"};
if (isset($profileJson->{"assessment-id"})) {
$id = Token::decode($profileJson->{"assessment-id"});
} else {
$id = Token::generateNewToken(TOKEN_ASSESSMENT);
}
$name = $profileJson->{"assessment-name"};
$displayname = isset($profileJson->{"display-name"}) ? $profileJson->{"display-name"} : $name;
$profile = new AssessmentProfile($id, $name, $displayname);
$questions = [];
foreach ($assessment->{"questions"} as $questionData) {
$questionJson = obj_to_array($questionData);
if (isset($questionData->{"question-id"})) {
$questionId = Token::decode($questionData->{"question-id"});
} else {
$questionId = Token::generateNewToken(TOKEN_QUESTION);
}
$question = [];
$question["id"] = $questionId->toString();
$question["data"] = $questionJson;
$questions[] = $question;
}
return ["assessment" => AssessmentBackend::create_assessment($profile, $questions)->toExternalForm()];
}
示例2: getAllForSchemaOption
/**
* 获得全部文章分类--无限极分类(编辑菜单时选项)
*
* @descript 递归组合无限极分类,为了编辑页面和增加页面select 展示
* @param $name 表单name名称
* @param $id 当前id
* @return array
* @author yangyifan <yangyifanphp@gmail.com>
*/
public static function getAllForSchemaOption($name, $id = 0, $first = true)
{
//加载函数库
load_func('common');
$data = $id > 0 ? merge_tree_node(obj_to_array(self::where('id', '<>', $id)->where('user_info_id', '=', is_user_login())->where('deleted_at', '=', '0000-00-00 00:00:00')->get())) : merge_tree_node(obj_to_array(self::where('user_info_id', '=', is_user_login())->get()));
$first == true && array_unshift($data, ['id' => '0', $name => '顶级分类']);
return $data;
}
示例3: getAllCategory
/**
* 获得全部分类
*
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public static function getAllCategory()
{
//加载函数库
load_func('common');
$data = obj_to_array(self::all());
$data = array_to_obj(merge_tree_child_node($data));
return $data;
}
示例4: getUserForumCat
/**
* 获得当前栏目全部角色权限
*
* @param null $role_id
* @return mixed
* @author yangyifan <yangyifanphp@gmail.com>
*/
public static function getUserForumCat($forum_cat_id)
{
if (!empty($forum_cat_id)) {
//加载函数库
load_func('common');
return obj_to_array(DB::table('forum_access AS fa')->select('r.id', 'r.role_name')->join('role AS r', 'fa.role_id', '=', 'r.id')->where('fa.forum_cat_id', '=', $forum_cat_id)->get());
}
return false;
}
示例5: obj_to_array
function obj_to_array($obj)
{
$array = is_object ? (array) $obj : $obj;
foreach ($array as $k => $v) {
if (is_object($v) or is_array($v)) {
$array[$k] = obj_to_array($v);
}
}
return $array;
}
示例6: saveUserSession
/**
* 写入用户信息到SESSION
*
* @param $user_info
* @author yangyifan <yangyifanphp@gmail.com>
*/
private static function saveUserSession($user_info)
{
//引入函数库
load_func('common');
$user_info = obj_to_array($user_info);
$user_info['user_user_data'] = ['id' => $user_info['id'], 'email' => $user_info['email'], 'updated_at' => $user_info['updated_at']];
$user_info['sign'] = hash_user_sign($user_info['user_user_data']);
Session::put('user_info', $user_info);
Session::save();
}
示例7: handlePost
private function handlePost($data)
{
$this->validate_request(["question"]);
$profile = AssessmentBackend::fetch_assessment_profile(Token::decode($this->params['id']));
$questionId = Token::decode($this->params['question']);
$question = [];
$question["id"] = $questionId->toString();
$question["data"] = obj_to_array($data->{"question"});
AssessmentBackend::update_question($profile, $questionId, $question);
return $this->handleGet($data);
}
示例8: getUserChoseCagetory
/**
* 获得全部分类
*
* @return mixed
* @author yangyifan <yangyifanphp@gmail.com>
*/
public static function getUserChoseCagetory()
{
//加载函数库
load_func('common');
//获得当前用户全部新闻分类
$user_new_category_id = self::getUserCagetory();
$all_category = self::all();
if (!empty($all_category)) {
foreach ($all_category as &$category) {
$category->checked = in_array($category->id, $user_new_category_id) ? true : false;
}
}
$all_category = obj_to_array($all_category);
return array_to_obj(merge_tree_child_node($all_category));
}
示例9: get_slider
/**
* 顯示滑動圖.
*/
function get_slider()
{
//滑動頁數量
$_int_count_slider = 5;
//取得文章資料
$_obj_posts = get_posts(array('numberposts' => $_int_count_slider, 'meta_key' => '_thumbnail_id'));
//將物件轉陣列
$_arr_posts = obj_to_array($_obj_posts);
//取得特色圖網址
foreach ($_arr_posts as $val) {
$val['url_thumb_img'] = wp_get_attachment_url(get_post_thumbnail_id($val['ID']));
$_arr_slider_posts[] = $val;
}
include_once 'slider.php';
}
示例10: getFullUserMenu
/**
* 获得组合用户全部分类[组合好]
*
* @param null $role_id
* @return array
* @author yangyifan <yangyifanphp@gmail.com>
*/
public static function getFullUserMenu($role_id = null)
{
//加载函数库
load_func('common');
$role_id = self::getRoleId($role_id);
$all_menu = self::where('deleted_at', '=', '0000-00-00 00:00:00')->get();
$all_user_menu = self::getUserRelationMenu($role_id);
if (!empty($all_menu)) {
foreach ($all_menu as &$menu) {
$menu->checked = in_array($menu->id, $all_user_menu) ? true : false;
}
}
//组合数据
$all_menu = merge_tree_child_node(obj_to_array($all_menu));
return array_to_obj($all_menu);
}
示例11: handle
public function handle($data)
{
$this->validate_request(["question"]);
$assessment = AssessmentBackend::fetch_assessment_profile(Token::decode($this->params['id']));
$questionJson = obj_to_array($data->{"question"});
if (isset($data->{"question"}->{"question-id"})) {
$questionId = Token::decode($data->{"question"}->{"question-id"});
} else {
$questionId = Token::generateNewToken(TOKEN_QUESTION);
}
$question = [];
$question["id"] = $questionId->toString();
$question["data"] = $questionJson;
AssessmentBackend::add_question($assessment, $question);
return [];
}
示例12: is_express
/**
* 快递模块
*
* @access public
* @param string $str
* @return string
*/
function is_express($str)
{
if (is_numeric($str)) {
$postid = strlen($str);
switch ($postid) {
case 10:
$type = "yuantong";
break;
case 12:
$type = "shunfeng";
break;
case 13:
$type = "yunda";
break;
}
if (isset($type)) {
$data = obj_to_array(json_decode(express($type, $str)));
return get_express_data($data);
}
}
}
示例13: getCategories
/**
* @return array
*/
public function getCategories()
{
return ["select"] + obj_to_array(get_terms('category', array('hide_empty' => 0)), 'term_id', 'name');
}
示例14: getForumLocation
/**
* 获得全部论坛分类
*
* @param $data
* @author yangyifan <yangyifanphp@gmail.com>
*/
public static function getForumLocation($data)
{
//加载函数库
load_func('common');
$all_category = obj_to_array(self::select('cat_name', 'id', 'pid')->get());
$data = get_location($all_category, $data->forum_cat_id);
//翻转函数
$data = array_reverse($data);
return $data;
}
示例15: obj_to_array
/**
* 对象转数组
*
* @access public
* @param object $obj
* @return array
*/
function obj_to_array($obj)
{
$ret = array();
foreach ($obj as $key => $value) {
if (gettype($value) == 'array' || gettype($value) == 'object') {
$ret[$key] = obj_to_array($value);
} else {
$ret[$key] = $value;
}
}
return $ret;
}