[英]Multidimensional Array key reference
我有一個多維數組,給我這個:
[ShipmentServiceLevelCategory] => test
[OrderTotal] => Array
(
[Amount] => 11.11
[CurrencyCode] => GBP
)
[ShipServiceLevel] => Std UK Dom
[MarketplaceId] => test
[ShippingAddress] => Array
(
[Phone] => 123213213213
[PostalCode] => TES T12
[Name] => Test
[CountryCode] => GB
[StateOrRegion] => Test
[AddressLine1] => Test
[City] => Test
)
我想將此信息插入數據庫中,但列名與數組鍵不同,因此我試圖創建另一個包含鍵映射的數組。 到目前為止,這是我嘗試過的:
$map = array('ShippingAddress['Phone']' => 'DEL_PHONE','ShippingAddress['PostalCode']'=> 'DEL_POSTCODE','ShippingAddress['Name']' => 'DEL_NAME');
但是,這給了我一個語法錯誤,有人可以指出我在哪里出錯了嗎?
$map = array('ShippingAddress' => array (
'Phone' => 'DEL_PHONE',
'PostalCode' => 'DEL_POSTCODE',
'Name' => 'DEL_NAME'
) );
這是獲取當前數組值並在其他數組中使用它們的正確語法
$new_array = array();
$new_array['DEL_PHONE'] = $current_array['ShippingAddress']['Phone'];
$new_array['DEL_POSTCODE'] = $current_array['ShippingAddress']['PostalCode'];
那應該給你一個關於如何繼續的好主意
您可以像這樣制作一個數組:
define("DEL_PHONE", "col1");
define("DEL_NAME", "col2");
$attributes = array(
DEL_PHONE => $data['ShippingAddress']['Phone'],
DEL_NAME => $data['ShippingAddress']['PostalCode']
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.