Hi, I would really appreciate if I could be helped on the following PHP code.
I have two arrays.
1) $user
2) $usertotal
$user can have as many names stored in it.
Example:
$user[0]="John";
$user[1]="Sean";
$user[2]="Nick";
$user[3]="Jay";
................
................
Similary,
$usertotal can have as many amount stored in it.
Example:
$usertotal[0]=100;
$usertotal[1]=50;
$usertotal[2]=150;
$usertotal[3]=0;
................
................
I am trying to build a finance related program where for example : they all go on a vacation and promise to divide the total expense of the vacation evenly among themselves (later). When they started, not all of them had equal amount of money with them.
$user[i] has spent $usertotal[i] amount of money. For example in this case, John spent 100 dollars and Jay spent 0 dollars.
I also have a variable $average which is the average of all amount based on the number of users.
Now, what i am trying to do is keep a record of how much one user owes to another user since they promised to divide the total among themselves and each guy has to pay the average.
I am trying to compare each person's expense with $average and based on the difference the person should either pay to another person or receive money from another person based on how much he spent.
Logic :
// the average is 100+50+150+0 = 300/4 = 75
// Since John paid 100 he has to receive (100-75=25) from the rest of the guys.
// Sean paid only 50, so he has to pay 25 to either John or Nick
// Nick spent 150 so he needs 75 payback from the rest.
// Jay did not have money during the trip so now he owes 75 to someone who alredy spent more than 75 (may be Nick and John). he should also be able to break it down and pay multiple persons if need be.
---------------------------------------------------------------------------------------
OUTPUT :
Sean has to pay 25 to John
Jay has to pay 75 to Nick
---------------------------------------------------------------------------------------
See, this way all of the guys ended up paying 75 as their part.
Suggestions and ideas would be highly appreciated. Thanks in advance.