简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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