2016-11-21 45 views
1

我想獲得陣列像下面如何獲取另一個數組的值?

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獲得關鍵作爲顏色和RAM的id和值id。在option display我得到了關鍵的顏色和RAM,但我不知道如何獲得值(即黑色和2GB)。我想獲得價值不id我必須爲此做。

回答

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>'; 
      } 
+0

我得到了相同的輸出。我只想得到option_display ....的值,但是我的輸出是這樣的[6] => Array([product_id] => 14 [price] => 10010.0000 [quantity] => 3 [option] => Array([option_display] => Array([Color] => [RAM] => [option_details] => Array([5] => 13 [6] => 16))) – Vinothini

+0

顏色和RAM爲空 – Vinothini

+0

In你使用下面的方法得到值的foreach循環beetween回聲$ value [option_display] [Color]; –

相關問題