访问与php特殊名称函数同名的对象值

时间:2015-09-06 20:56:44

标签: php arrays wordpress object woocommerce

我有一个对象数组

       [1] => Array
            (
                [0] => stdClass Object
                    (
                        [term_id] => 21
                        [name] => House
                        [slug] => house
                        [term_group] => 0
                        [term_taxonomy_id] => 21
                        [taxonomy] => product_cat
                        [description] => 
                        [parent] => 16
                        [count] => 2
                        [filter] => raw
                    )

                [1] => stdClass Object
                    (
                        [term_id] => 12
                        [name] => stone
                        [slug] => stone
                        [term_group] => 0
                        [term_taxonomy_id] => 12
                        [taxonomy] => product_cat
                        [description] => 
                        [parent] => 8
                        [count] => 1
                        [filter] => raw
                    )

            )

我需要检查[parent]值。 但是,当父母提到http://php.net/manual/en/keyword.parent.php

使用类似的东西:

foreach ($array_entry as $object) {
 if ($object->parent === $something) {
     ....
   } else {
     ....
   }
}

不起作用。 如何访问父值? 我尝试了'parent'仍然无效。

2 个答案:

答案 0 :(得分:1)

试试这个:

  foreach($array_entry as $key => $object){
    print_r($object->parent);
  }

答案 1 :(得分:1)

试试这个:

foreach ($array_entry as $object) {
    var_dump( $object->{'parent'} );
}