我有一個2d數組。取一個數組,並添加一個字段與來自數組的數據
$original_array = array();
// amount/funding_by/withdrawing_by/bank_name_1/bank_name_2
$original_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "ANZ");
$original_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "BOA");
$original_array[] = array("100","Cash","Bank Deposit", "Chase", "BOA");
$original_array[] = array("100","Bank Deposit","Cash", "Chase", "BOA");
$original_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "JP Morgan");
我想添加通過取funding_by和withdrawing_by字段,並用「到」分離形成的附加字段(funding_by_to_withdrawing_by)。 也就是說。銀行存款到銀行存款
最後,我想壓縮數組,檢查數額bank1_name和bank_2_name是否都與另一行相匹配,如果是,則將原始行的funding_by_to_withdrawing_by字段與副本的funding_by_to_withdrawing_by字段相加行。
重複行隨後被刪除,所以處理的陣列看起來像這樣:
$processed_array = array();
// amount/funding_by/withdrawing_by/bank_name_1/bank_name_2/funding_by_to_withdrawing_by
$processed_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "ANZ", "Bank Deposit to Bank Deposit");
$processed_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "BOA", "Bank Deposit to Bank Deposit, Cash to Bank Deposit, Bank Deposit to Cash");
$processed_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "JP Morgan");
我已經試過這一點,但是說實話,我只是得到了更多的疑惑,這是行不通的:
$original_array = array();
// amount/funding_by/withdrawing_by/bank_name_1/bank_name_2
$original_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "ANZ");
$original_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "BOA");
$original_array[] = array("100","Cash","Bank Deposit", "Chase", "BOA");
$original_array[] = array("100","Bank Deposit","Cash", "Chase", "BOA");
$original_array[] = array("100","Bank Deposit","Bank Deposit", "Chase", "JP Morgan");
$processed_array = array();
foreach($original_array as $submitted_data)
{
foreach($processed_array as $verified_data)
{
if ($submitted_data[0]==$verified_data[0])
{
$duplicate_found = true;
$listoffundingtowithdrawalmethods = "$fundingname to $withdrawalname<br>" . $submitted_data[1] . " to " . $submitted_data[2];
array_push($verified_data, "$listoffundingtowithdrawalmethods");
$processed_array[] = $verified_data;
}
else
{
$duplicate_found = "";
}
}
if ($duplicate_found != true)
{
$listoffundingtowithdrawalmethods = "$fundingname to $withdrawalname<br>";
array_push($submitted_data, "$listoffundingtowithdrawalmethods");
$processed_array[] = $submitted_data;
}
}
然而它仍然不是很正確。我希望你們能夠有所作爲。
謝謝你的時間!
馬特
由於您的原始數組沒有任何種類的唯一標識符,因此您似乎可能擁有似乎是重複的條目,但實際上是不同的事務。那可能嗎? –
感謝您的關注!它們實際上不是交易,它們是送錢的方式(銀行存款,現金等到銀行存款,現金),以及如果您發送了錢,您會得到什麼。所以,如果一種方式發送金錢獲得與另一種方式相同的金額,我想將其壓縮成一行。 –
啊,好的。我懂了。 –