PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$masterData = array();
//this shows the name, email, deposit date and amount from payment.csv
$data = file("datas/payment.csv");
foreach ($data as $deposit){
$depositarray = explode(",", $deposit);
$depositlist = $depositarray;
$key = md5($depositlist[9] . $depositlist[10]); //date + amount
$masterData[$key]['payment'] = array(
'name' => $depositlist[0],
'email' => $depositlist[1],
'depositdate' => $depositlist[9],
'depositamount' => $depositlist[10]
);
}
//this shows the payment date and amount from transaction.csv
$databank = file("datas/transactions.csv");
foreach ($databank as $payment){
$paymentarray = explode(",", $payment);
$paymentlist = $paymentarray;
$key = md5($paymentlist[0] . $paymentlist[5]); //date + amount
$masterData[$key]['transaction'] = array(
'paymentdate' => $paymentlist[0],
'paymentamount' => $paymentlist[5]
}
Would it be possible to display/store in arrays all transaction that have multiple matched? Example: Payment A match to Transaction 1, 3, 5.. so on. Purpose is to view all possible match of a payment in transaction.
Attachments
Last edited by xkevin on Thu Jun 09, 2016 11:05 pm, edited 1 time in total.
Right now you're only allowing for one transaction per $key. Make ['transaction'] be an array, and add each matching transaction to it. So your data will look like
requinix wrote:Right now you're only allowing for one transaction per $key. Make ['transaction'] be an array, and add each matching transaction to it. So your data will look like
Yes, that should be the output. But where I can put that code? Inside the loop? Would you mind giving me reference. Arrays and loop is headache for me. Thank you!
That is where you are putting the transaction data array into the main array. Instead of going into ['transaction'] directly, make ['transaction'] a plain array and then put the transaction data array into that.
Try writing something and see what happens. If you have problems, post your code and a description of what is going wrong.
That is where you are putting the transaction data array into the main array. Instead of going into ['transaction'] directly, make ['transaction'] a plain array and then put the transaction data array into that.
Try writing something and see what happens. If you have problems, post your code and a description of what is going wrong.
Thank you for that. I just added []. $masterData[$key]['transaction'] [] = array
Yes, that is probably the way to do it. I noticed a couple things about your code. First, md5(date+amount) is not a very unique value -- you should probably use md5(name+email+date+amount). Otherwise you will have transactions that had the same amounts on the same day overwritten. Second, the date is redundant in the transaction data. It just takes up memory if you will have large arrays.
Christopher wrote:Yes, that is probably the way to do it. I noticed a couple things about your code. First, md5(date+amount) is not a very unique value -- you should probably use md5(name+email+date+amount). Otherwise you will have transactions that had the same amounts on the same day overwritten. Second, the date is redundant in the transaction data. It just takes up memory if you will have large arrays.
-I intended to do it like that because my primary purpose is to display all possible match (date and amount) of transaction list. So all transaction that has match in payment will display. But my last problem is on how to display the all the matched array on top. Or be separated from no matched.
There are several ways to do what you want. Perhaps the simplest would be to put the values into two different arrays in your loop -- one array for matched and one array for unmatched. Is there a reason they need to be in on array. If so then use the array sort method with a callback.
Christopher wrote:There are several ways to do what you want. Perhaps the simplest would be to put the values into two different arrays in your loop -- one array for matched and one array for unmatched. Is there a reason they need to be in on array. If so then use the array sort method with a callback.
I already fixed it. But I have bottleneck now. I want to sort the array by date, so that when the data was display n table it is sorted by date ascending.
Try adding this but no success. It just display base on the order data of the payment.csv file.