0

我有一个多维数组,它给了我这个:

            [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');

但是,这给了我一个语法错误,有人可以指出我在哪里出错了吗?

4

3 回答 3

0
$map = array('ShippingAddress' => array (
'Phone' => 'DEL_PHONE',
'PostalCode' => 'DEL_POSTCODE',
'Name' => 'DEL_NAME' 
) );
于 2013-07-26T13:36:14.377 回答
0

这是获取当前数组值并在不同数组中使用它们的正确语法

$new_array = array();

$new_array['DEL_PHONE'] = $current_array['ShippingAddress']['Phone'];

$new_array['DEL_POSTCODE'] = $current_array['ShippingAddress']['PostalCode'];

这应该给你一个关于如何继续的好主意

于 2013-07-26T13:37:24.103 回答
0

你可以像这样创建一个数组:

define("DEL_PHONE", "col1");
define("DEL_NAME", "col2");
$attributes = array(
DEL_PHONE => $data['ShippingAddress']['Phone'],
DEL_NAME => $data['ShippingAddress']['PostalCode']
);
于 2013-07-26T13:37:47.403 回答