我从postmeta获取post_id为:$post_id = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE (meta_key = 'mfn-post-link1' AND meta_value = '". $from ."')");当我尝试print_r($post_id); 我有这样的数组:Array( [0] => stdClass Object ( [post_id] => 140 ) [1] => stdClass Object ( [post_id] => 141 ) [2] => stdClass Object ( [post_id] => 142 ))而且我不知道如何遍历它,如何获得这样的数组Array( [0] => 140 [1] => 141 [2] => 142)知道我该怎么做吗?
3 回答
![?](http://img1.sycdn.imooc.com/5458478b0001f01502200220-100-100.jpg)
拉丁的传说
TA贡献1789条经验 获得超8个赞
很简单,首先将您的对象转换为json对象,这会将您的对象字符串转换为JSON代表。
获取该结果并使用额外的参数true解码,它将转换为关联数组
$array = json_decode(json_encode($oObject),true);
![?](http://img1.sycdn.imooc.com/54584c9c0001489602200220-100-100.jpg)
慕的地8271018
TA贡献1796条经验 获得超4个赞
尝试这个:
$new_array = objectToArray($yourObject);
function objectToArray($d)
{
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
} else {
// Return array
return $d;
}
}
- 3 回答
- 0 关注
- 539 浏览
添加回答
举报
0/150
提交
取消