Php ant是关于学习映射和查询转换等新事物的。 Array ( [Key] => R******l [Password] => c*************z [AccountNumber] => 0****1
ant是关于学习映射和查询转换等新事物的。Php ant是关于学习映射和查询转换等新事物的。 Array ( [Key] => R******l [Password] => c*************z [AccountNumber] => 0****1 ,php,sql-server,soap-client,php-7.2,Php,Sql Server,Soap Client,Php 7.2,ant是关于学习映射和查询转换等新事物的。 Array ( [Key] => R******l [Password] => c*************z [AccountNumber] => 0****1 [MeterNumber] => 2******5 [ShipTimestamp] => 2020-10-29T10:24:19+01:00 [ServiceType] => INTERNATIONAL_EC
Array
(
[Key] => R******l
[Password] => c*************z
[AccountNumber] => 0****1
[MeterNumber] => 2******5
[ShipTimestamp] => 2020-10-29T10:24:19+01:00
[ServiceType] => INTERNATIONAL_ECONOMY
[PackagingType] => YOUR_PACKAGING
[PreferredCurrency] => EUR
[Weight_Units] => KG
[TotalWeight] => 0.02
...
)
Array
(
[Authentication] => Array
(
[User] => Array
(
[Key] => R******l
[Password] => c*************z
)
)
[Client] => Array
(
[Account] => 0*******1
[Meter] => 2*******5
)
[Shipment] => Array
(
[ShipTimestamp] => 2020-10-29T10:41:26+01:00
[DropoffType] => REGULAR_PICKUP
[ServiceType] => INTERNATIONAL_ECONOMY
[PackagingType] => YOUR_PACKAGING
[PreferredCurrency] => EUR
[TotalWeight] => Array
(
[Units] => KG
[Value] => 0.02
)
)
...
)
$data = [
'Key' => 'R******l',
'Password' => 'c*************z',
'AccountNumber' => '0****1',
'MeterNumber' => '2******5',
'ShipTimestamp' => '2020-10-29T10:24:19+01:00',
'ServiceType' => 'INTERNATIONAL_ECONOMY',
'PackagingType' => 'YOUR_PACKAGING',
'PreferredCurrency' => 'EUR',
'Weight_Units' => 'KG',
'TotalWeight' => '0.02',
];
$mapping = [
'Key' => ['name' => 'Key', 'group' => ['Authentication', 'User']],
'Password' => ['name' => 'Password', 'group' => ['Authentication', 'User']],
'AccountNumber' => ['name' => 'Account', 'group' => ['Client']],
'MeterNumber' => ['name' => 'Meter', 'group' => ['Client']],
'ShipTimestamp' => ['name' => 'ShipTimestamp', 'group' => ['Shipment']],
'ServiceType' => ['name' => 'ServiceType', 'group' => ['Shipment']],
'PackagingType' => ['name' => 'PackagingType', 'group' => ['Shipment']],
'PreferredCurrency' => ['name' => 'PreferredCurrency', 'group' => ['Shipment']],
'Weight_Units' => ['name' => 'Units', 'group' => ['Shipment', 'TotalWeight']],
'TotalWeight' => ['name' => 'Value', 'group' => ['Shipment', 'TotalWeight']],
];
$mappedData = [];
foreach($data as $key => $value) {
$map = $mapping[$key];
$root = array_shift($map['group']);
krsort($map['group']);
$value = [$map['name'] => $value];
foreach($map['group'] as $group) {
$value = [$group => $value];
}
$new[$root] = $value;
$mappedData = array_replace_recursive ($mappedData, $new);
}
Array
(
[Authentication] => Array
(
[User] => Array
(
[Key] => R******l
[Password] => c*************z
)
)
[Client] => Array
(
[Account] => 0****1
[Meter] => 2******5
)
[Shipment] => Array
(
[ShipTimestamp] => 2020-10-29T10:24:19+01:00
[ServiceType] => INTERNATIONAL_ECONOMY
[PackagingType] => YOUR_PACKAGING
[PreferredCurrency] => EUR
[TotalWeight] => Array
(
[Units] => KG
[Value] => 0.02
)
)
)