douli0531 2016-08-23 09:43
浏览 64

Wordpress - 访问Array中的Wp对象并检索所有ID

I've created a query getting only some users with specific criteria. I store these users into an array. My problem is to get back from this array only specific values like ids.

I print_r my function myfriends() and I get something like this:

Array ( 
[0] => Array ( 
    [0] => Array ( 
        [0] => WP_User Object ( 
            [data] => stdClass Object ( 
                [ID] => 48 
                ) 
            ) 
        [1] => WP_User Object ( 
            [data] => stdClass Object ( 
                [ID] => 47 
                ) 
            ) 
    ) 
[1] => 
) 

)

I need to retrieve all the ids of users in array so I've tried with:

$myfriends = myfriends($user_id); //good

$myfriendsids = $myfriends->ID; //not working
$myfriendsids = $myfriends[0]->ID; //not working
$myfriendsids = $myfriends[0][0]->ID; //not working
$myfriendsids = $myfriends[0][0][0]->ID; //only the first user id!

//even tried
$myuserdata = $myfriends->data; //not working
$myuserids = $myuserdata->ID; //not working

How can I get all the user ids I have? NB. "not working" means that I print_r all the variables and I get nothing. Thanks!

  • 写回答

1条回答 默认 最新

  • dsv17139 2016-08-23 10:24
    关注

    Tweaking a bit I've accessed and stored ids values with a foreach loop in $myfriendsids. Cool.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用