【问题标题】:Accessing an object's value that has the same name as a php special name function访问与 php 特殊名称函数同名的对象的值
【发布时间】:2015-09-06 20:56:44
【问题描述】:

我有一个对象数组

       [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' 还是不行。

【问题讨论】:

    标签: php arrays wordpress object woocommerce


    【解决方案1】:

    试试这个:

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

    【讨论】:

      【解决方案2】:

      试试这个:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-05
        • 1970-01-01
        • 2012-06-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多