如何获得另一个数组的值?

时间:2016-11-21 12:52:28

标签: php magento-1.9

我想获得如下的数组

Array (
[0] => Array (
        [product_id] => 6
        [price] => 50.0000
        [quantity] => 5
        [option] => Array (
                [option_display] => Array (
                        [Color] => black
                        [RAM] => 2GB
                    )

                [option_details] => Array (
                        [7] => 15
                        [8] => 16
                    )

            )

    )

[1] => Array
    (
        [product_id] => 6
        [price] => 50.0000
        [quantity] => 4
        [option] => Array
            (
                [option_display] => Array
                    (
                        [Cover Type] => flip
                        [Description] => leather type
                    )

                [option_details] => Array
                    (
                        [7] => flip
                        [8] => leather type
                    )

            )

    ) )

在上面的代码中,option_display是要显示的值,并在option_details id中存储在db中。(注意:flipleather type是字段和文本区域 15和16是选择框和单选框,因此它有id)

我的html文件是

case 'drop_down':
            echo $value->getTitle();
            echo '<input type="hidden" name="option_display['.$value->getTitle().']" id="option_display_'.$value->getTitle().'" />';
            echo '<div><p class="'.(($value->getIsRequire() == 1) ? 'required' : '').'">'.(($value->getIsRequire() == 1) ? '*Required Field' : '').'</p><select name="option_value['.$value->getOptionId().']">';
            foreach ($option as $values) {
                echo '<option value="'.$values['option_type_id'].'" id="option_value_'.$value->getOptionId().'">'.$values['title'].' + '.Mage::helper('core')->currency($values['price'], true, false).'</option>';
            }
            echo '</select></div>';
            break;

我有数组值

$newdata        = array (
            'product_id' => $product_id,
            'price'      => $price,
            'quantity'   => $quantity,
            'option'     => array(
                'option_display' => $option_display,
                'option_details' => $option_value
                )
        );

option_details获取密钥作为颜色的ID和RAM和值id。在option display我得到了关键的颜色和RAM,但我不知道如何获得值(即黑色和2gb)。我想得到的数字不是我必须做的事情。

1 个答案:

答案 0 :(得分:1)

  

将foreach循环更改为以下方法: -

   foreach ($option as $values => $value) {
                echo '<option value="'.$value['option_type_id'].'" id="option_value_'.$value->getOptionId().'">'.$value['title'].' + '.Mage::helper('core')->currency($values['price'], true, false).'</option>';
            }