Suneth Kalhara Suneth Kalhara - 2 years ago 59
PHP Question

PHP extract value form a variable

I'm working on WordPress plugin, It have a variable called $item, which holds some data of a post.

I use var_dump function to display it's data,

var_dump($item);


but i couldn't able to get a value of a single item.

I just need to get item_id and item_order

Can someone help me to get this values and assign to a another variable.
Thank You

Here is the dump

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) "

Answer Source

since it is an object, just echo

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download