PHP 提取值形成一个变量



我正在开发WordPress插件,它有一个名为$item的变量,其中包含帖子的一些数据。

我使用var_dump函数来显示它的数据,

var_dump($item);

但我无法获得单个项目的值。

我只需要item_iditem_order

有人可以帮助我获取此值并分配给另一个变量吗? 谢谢

这是转储

object(LP_Lesson)#11313 (5) { 
["id"]=> int(6915) 
["post"]=> object(WP_Post)#11357 (29) { 
["ID"]=> int(6915) ["post_author"]=> string(1) "1" 
["post_date"]=> string(19) "2015-06-05 04:29:56" ["post_date_gmt"]=> string(19) "2015-06-05 04:29:56" ["post_content"]=> string(5971) "" ["post_title"]=> string(20) "Add and manage users" ["post_excerpt"]=> string(1) " " ["post_status"]=> string(7) "publish" 
["post_parent"]=> int(0) ["guid"]=> string(66) "test" ["menu_order"]=> int(0) ["post_type"]=> string(9) "lp_lesson" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" ["section_item_id"]=> string(1) "3" 
["section_id"]=> string(1) "1" 
["item_id"]=> string(4) "6915" 
["item_order"]=> string(1) "3" 
["item_type"]=> string(9) "lp_lesson" } 
["content"]=> string(0) "" ["lesson_type"]=> NULL ["_item":protected]=> object(WP_Post)#11357 (29) { ["ID"]=> int(6915) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2015-06-05 04:29:56" ["post_date_gmt"]=> string(19) "2015-06-05 04:29:56" ["post_content"]=> string(5971) "

因为它是一个对象,所以只是回显

$item->id&$item->post->item_order

你试过吗:

$item_id = $item->item_id

$item->post->item_order; //as instructed by @AliAwwad

? 顺便说一句,我看到 id 与 item_id 相同,因此您肯定可以这样做:

$item_id = $item->id;

是否有一些我看不到的范围指示?

最新更新