简体   繁体   English

多维数组键参考

[英]Multidimensional Array key reference

I have a multidimensional array that gives me this: 我有一个多维数组,给我这个:

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

I want to insert this information into my DB but my column names are different from the array keys so I am trying to create another array that contains the key mappings. 我想将此信息插入数据库中,但列名与数组键不同,因此我试图创建另一个包含键映射的数组。 Here is what I have tried so far: 到目前为止,这是我尝试过的:

$map = array('ShippingAddress['Phone']' => 'DEL_PHONE','ShippingAddress['PostalCode']'=> 'DEL_POSTCODE','ShippingAddress['Name']' => 'DEL_NAME');

However this gives me a syntax error, can somebody point out where I'm going wrong here? 但是,这给了我一个语法错误,有人可以指出我在哪里出错了吗?

$map = array('ShippingAddress' => array (
'Phone' => 'DEL_PHONE',
'PostalCode' => 'DEL_POSTCODE',
'Name' => 'DEL_NAME' 
) );

Here is the correct syntax to get current array values and use them in different array 这是获取当前数组值并在其他数组中使用它们的正确语法

$new_array = array();

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

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

That should give you a good idea on how to continue 那应该给你一个关于如何继续的好主意

You can make an array like this: 您可以像这样制作一个数组:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM