访问与 php 特殊名称函数同名的 object 值
Accessing an object's value that has the same name as a php special name function
我有一个 objects
的数组
[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]
值。
但是因为 parent 指的是 http://php.net/manual/en/keyword.parent.php
使用类似的东西:
foreach ($array_entry as $object) {
if ($object->parent === $something) {
....
} else {
....
}
}
不起作用。
如何访问 parent 值?
我试过 'parent'
还是不行。
试试这个:
foreach($array_entry as $key => $object){
print_r($object->parent);
}
试试这个:
foreach ($array_entry as $object) {
var_dump( $object->{'parent'} );
}
我有一个 objects
的数组 [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]
值。
但是因为 parent 指的是 http://php.net/manual/en/keyword.parent.php
使用类似的东西:
foreach ($array_entry as $object) {
if ($object->parent === $something) {
....
} else {
....
}
}
不起作用。
如何访问 parent 值?
我试过 'parent'
还是不行。
试试这个:
foreach($array_entry as $key => $object){
print_r($object->parent);
}
试试这个:
foreach ($array_entry as $object) {
var_dump( $object->{'parent'} );
}