2017-08-16 60 views
0

我正在使用WordPress插件,它有一個變量,名爲$ item,它包含一些文章的一些數據。PHP提取值形成一個變量

我用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) " 
+1

你嘗試過什麼到目前爲止,訪問你需要 – Regolith

+1

自PHP對象不是它只是'$用品 - > ITEM_ID數據'? – Deckerz

+1

你試過'$ item-> id'&'$ item-> post-> item_order'嗎? – AliAwwad

回答

1

,因爲它是一個對象,只是呼應

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

1

你嘗試:

$item_id = $item->item_id 

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

? 順便說一句,我看到的ID,是ITEM_ID一樣的,所以這是肯定你可以這樣做:

$item_id = $item->id; 

有沒有辦法,我沒有看到一些範圍指示?

+0

這是一個對象,因此以數組的形式訪問它是行不通的。 – jeroen

+0

謝謝指出!過去幾周我一直在前後回到python,我的語法變得混亂起來! – Orestes