【发布时间】:2020-12-19 07:08:37
【问题描述】:
截图
如您所见,我的数据已加载到额外的 SNHISTORY 数组中,我需要删除该额外的数组。
代码
关于截图结果的行被注释了。
$array = [];
foreach($internalTransits as $key => $item) {
foreach($item->barcodes as $barcode){}
$a = $item->barcodes;
$grouped = $a->mapToGroups(function ($item, $key) {
return [
'SNHISTORY' => [ // my arrays to move out
'_attributes' => [
'operation' => 'Ret'
],
'SERIALNUMBER' => $item['serial_number'] ? $item['serial_number'] : $item['u_serial_number'],
'EXPIREDDATE' => $item['created_at']->format('Y-m-d'),
'QUANTITY' => '1',
'SNSIGN' => '-1',
],
'ITEMUNIT' => $item['product']['unit'],
'UNITPRICE' => $item['product']['price'],
];
});
$year = Carbon::createFromFormat('Y-m-d H:i:s', $item['created_at'])->year;
$month = Carbon::createFromFormat('Y-m-d H:i:s', $item['created_at'])->month;
$timeline[$key][] = [
'_attributes' => [
'operation' => 'Add'
],
'KeyID' => $barcode['product']['id'],
'ITEMNO' => $barcode['product']['sku'],
'QUANTITY' => '1',
'ITEMUNIT' => $barcode['product']['unit'],
'UNITRATIO' => '1',
'ITEMRESERVED1' => '',
'ITEMRESERVED2' => '',
'ITEMRESERVED3' => '',
'ITEMRESERVED4' => '',
'ITEMRESERVED5' => '',
'ITEMRESERVED6' => '',
'ITEMRESERVED7' => '',
'ITEMRESERVED8' => '',
'ITEMRESERVED9' => '',
'ITEMRESERVED10' => '',
'UNITPRICE' => $barcode['product']['price'],
'QTYCONTROL' => '0',
'SNHISTORY' => $grouped->toArray(), // this has extra array where my actual arrays are loaded inside of it
];
$array['TRANSACTIONS'] = [
'_attributes' => [
'OnError' => 'CONTINUE'
],
];
$array['TRANSACTIONS']['WTRAN'] = [
'_attributes' => [
'operation' => 'Add',
'REQUESTID' => '1',
],
'TRANSFERID' => $item['id'],
'TRANSACTIONID' => '',
'TRANSFERNO' => $item['transNu'],
'TRANSFERDATE' => $item['created_at']->format('Y-m-d'),
'DESCRIPTION' => $item['description'],
'FROMWHID' => $barcode['outlet'][0]['name'],
'TOWHID' => $item->toOutlet->name,
'FROMWHADDRESS' => '',
'TOWHADDRESS' => '',
];
$array['TRANSACTIONS']['WTRAN']['ITEMLINE'] = $timeline;
}
我尝试过的
- 我无法在
$timeline[$key][] = [下将'SNHISTORY' => $grouped->toArray(),更改为$grouped->toArray(),之类的东西,它会返回错误 - 我无法添加
$array['TRANSACTIONS']['WTRAN']['ITEMLINE']['SNHISTORY'] = $grouped->toArray();和删除'SNHISTORY' => $grouped->toArray(),它将返回错误known bug
问题
如何删除数据周围的额外SNHISTORY?
【问题讨论】:
-
在您的屏幕截图中,您有需要转换为数组的 xml 数据
-
$timeline[$key][] = [...] + $grouped->toArray();?你想合并这些。 -
@KamleshPaul 是的,它正在将我的数据库数据转换为 xml,问题是我的数据不需要额外的
SNHISTORY。 -
@Jeto 抱歉,我没听懂你想说什么
-
I mean like this.(抱歉,没有 SNHISTORY 键,已编辑)