2012-12-20 64 views
5

我有了一些數據,看起來像這樣是否可以在PHP中的數組中組合兩個數組?

$valueOptions = array(
         'order_shipping_data_firstname' => Mage::helper('orders2csv')->__('order shipping firstname'), 
         'order_shipping_data_lastname' => Mage::helper('orders2csv')->__('order shipping lastname'), 
         'order_shipping_data_region' => Mage::helper('orders2csv')->__('order shipping region'), 
         'order_shipping_data_street' => Mage::helper('orders2csv')->__('order shipping street'), 
         'order_shipping_data_city' => Mage::helper('orders2csv')->__('order shipping city') 
       ); 

我需要的名字和姓氏字段合併,但不能想出一個解決方案的陣列。這是模塊中引用任何lastname/first name/name的唯一文件,因此它在magento框架內從外部調用它。理想情況下,它們將存儲在變量中,我可以將它們合併爲$ fullname = $ first。 $ last等,但這不適用於數組。

我不明白=>的用法太好,但是我知道如果我編輯右手邊並做出如下操作:=> Mage::helper('orders2csv')->__('order shipping fullname')該選項會出現在我想要的位置(在下拉列表中),所以我想我正在嘗試結合'order_shipping_data_firstname'&'order_shipping_data_lastname'並把它放在這之前,但在數組內?

我也試着在一個變量中開始另一個數組,並將變量插入到valueOptions數組中,但是這個打破了。

回答

3
$foo = array(
    'bar' => array(
     "hello", 
     "world" 
    ), 
); 
var_dump($foo); 

陣列嵌套在陣列

+0

你能給我怎樣,這將是適用於我的例子爲例。似乎Mage :: helper('orders2csv') - > __('order shipping street')部分呈現下拉菜單 - 所以我想我正在嘗試加入'order_shipping_data_firstname'和'order_shipping_data_lastname'派對,然後Mage :: helper('orders2csv') - > __('order shipping fullname'), – James

1

試試這個:

$orders = Mage::helper('orders2csv'); 
$valueOptions = array(
     'order_shipping_data_firstname' => $orders->__('order shipping firstname'), 
     'order_shipping_data_lastname' => $orders->__('order shipping lastname'), 
     'order_shipping_data_fullname' => $orders->__('order shipping firstname').' '.$orders->__('order shipping lastname'), 
     'order_shipping_data_region' => $orders->__('order shipping region'), 
     'order_shipping_data_street' => $orders->__('order shipping street'), 
     'order_shipping_data_city' => $orders->__('order shipping city') 
); 

或者這樣:

$orders = Mage::helper('orders2csv'); 
$valueOptions = array(
     'order_shipping_data_firstname' => $orders->__('order shipping firstname'), 
     'order_shipping_data_lastname' => $orders->__('order shipping lastname'), 
     'order_shipping_data_fullname' => $orders->__('order shipping fullname'), 
     'order_shipping_data_region' => $orders->__('order shipping region'), 
     'order_shipping_data_street' => $orders->__('order shipping street'), 
     'order_shipping_data_city' => $orders->__('order shipping city') 
); 
相關問題