【发布时间】:2013-07-05 14:51:44
【问题描述】:
我有一个数组。 print_r 这个数组的结果是这样的:
Array
(
[flat_rate] => WC_Shipping_Rate Object
(
[id] => flat_rate
[label] => book
[cost] => 8000
[taxes] => Array
(
)
[method_id] => flat_rate
)
[local_delivery] => WC_Shipping_Rate Object
(
[id] => local_delivery
[label] => dvd
[cost] => 15000
[taxes] => Array
(
)
[method_id] => local_delivery
)
)
我需要像这样创建数组。 我通过这段代码尝试这个数组:
Array("flat_rate" => (object) Array("id" => "flat_rate" ,"label" => "book" ,"cost" => 8000 ,"taxes" => Array ( ) ,"method_id" => "flat_rate") ,"local_delivery" => (object) Array("id" => "local_delivery" ,"label" => "book" ,"cost" => 15000 ,"taxes" => Array ( ) ,"method_id" => "local_delivery"));
但是当 print_r 这个数组时,WC_Shipping_Rate 会改变 stdClass
【问题讨论】:
-
你需要调用
WC_Shipping_Rate构造函数来获取该类型的对象。 -
为什么你需要它?
-
我需要在 wordpress 中更改 woocommerce 上的数组
-
如何调用WC_Shipping_Rate? :((
-
退后一步考虑一下您实际上要实现的目标可能是个好主意-“更改数组”听起来像是您为更大的问题提出的解决方案,而不是你为了它自己而想做的事情。这被称为the XY Problem。