打印 stdClass 对象 [英] Printing an stdClass object
本文介绍了打印 stdClass 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
$value = $wpdb->get_row("SELECT custom_message FROM `wp_wpsc_cart_contents` WHERE purchaseid='" . $purchase_log['id'] . "'");
如果我这样做:
print_r($value);
我明白了:
stdClass Object
(
[custom_message] => |Castor Seed Oil $4.45|
)
所以我试图获得那个价值:
So I tried to get that value doing:
foreach($value as $index => $result) {
echo $result["custom_message"];
}
我也试过:
foreach($value as $index => $result) {
echo $result->custom_message;
}
但是没有打印任何东西,知道我在这里做错了什么吗?
but that prints nothing, any idea what I'm doing wrong here?
推荐答案
循环什么都不做,你正在迭代一个具有单个属性的对象,你已经知道它的名称.只需这样做:
The loop does nothing, you are iterating an object with a single property that you already know the name of. Just do this:
echo $value->custom_message;
这篇关于打印 stdClass 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文