0
$i = 1;
 foreach ($product->getOptions() as $o) {
     $values = $o->getValues();
     foreach ($values as $v) {
            print_r($v->getData());
     }
     $i++;
 }

上面的代码输出以下结果:

Array
(
    [option_type_id] => 9
    [option_id] => 3
    [sku] => 
    [sort_order] => 0
    [default_title] => Black
    [store_title] => 
    [title] => Black
    [default_price] => 0.0000
    [default_price_type] => fixed
    [store_price] => 
    [store_price_type] => 
    [price] => 0.0000
    [price_type] => fixed
)
Array
(
    [option_type_id] => 7
    [option_id] => 3
    [sku] => 
    [sort_order] => 0
    [default_title] => Red
    [store_title] => 
    [title] => Red
    [default_price] => 0.0000
    [default_price_type] => fixed
    [store_price] => 
    [store_price_type] => 
    [price] => 0.0000
    [price_type] => fixed
)
Array
(
    [option_type_id] => 8
    [option_id] => 3
    [sku] => 
    [sort_order] => 0
    [default_title] => White
    [store_title] => 
    [title] => White
    [default_price] => 0.0000
    [default_price_type] => fixed
    [store_price] => 
    [store_price_type] => 
    [price] => 0.0000
    [price_type] => fixed
)

我想输出[title]值。我怎么做?谢谢你。我试过用$v->getData()['title'],但没有用。

4

1 回答 1

4

在php5.4之前,你不能这样做$v->getData()['title'],你需要使用一个变量。

$i = 1;
foreach ($product->getOptions() as $o) {
    $values = $o->getValues();
    foreach ($values as $v) {
        $data = $v->getData();
        echo $data['title'];
    }
    $i++;
}
于 2012-08-16T03:07:53.347 回答