How to calculate the current balance of every account number using php -
i have array below.the from field account number of person money is, second field amount of money,
, third field to account number of person money to. how can calculate current balance of every account number.
array ( [0] => array ( [from] => 314 [amount] => $470.21 [to] => 275 ) [1] => array ( [from] => 12 [amount] => $1,788.98 [to] => 149 ) [2] => array ( [from] => 316 [amount] => $2,949.53 [to] => 417 ) [3] => array ( [from] => 5 [amount] => $2,193.48 [to] => 454 ) [4] => array ( [from] => 198 [amount] => $1,402.76 [to] => 371 ) [5] => array ( [from] => 82 [amount] => $1,212.14 [to] => 420 ) [6] => array ( [from] => 222 [amount] => $1,167.72 [to] => 396 ) [7] => array ( [from] => 348 [amount] => $4,024.42 [to] => 399 ) [8] => array ( [from] => 474 [amount] => $1,216.86 [to] => 60 ) [9] => array ( [from] => 449 [amount] => $974.59 [to] => 422 ) [10] => array ( [from] => 415 [amount] => $232.12 [to] => 351 ) [11] => array ( [from] => 164 [amount] => $353.19 [to] => 42 ) [12] => array ( [from] => 321 [amount] => $4,202.13 [to] => 377 ) [13] => array ( [from] => 99 [amount] => $1,178.71 [to] => 51 ) [14] => array ( [from] => 251 [amount] => $3,015.86 [to] => 262 ) [15] => array ( [from] => 374 [amount] => $2,014.48 [to] => 299 ) [16] => array ( [from] => 351 [amount] => $2,807.71 [to] => 302 ) [17] => array ( [from] => 286 [amount] => $2,516.63 [to] => 166 ) [18] => array ( [from] => 110 [amount] => $464.08 [to] => 385 ) [19] => array ( [from] => 171 [amount] => $1,623.41 [to] => 452 ) [20] => array ( [from] => 293 [amount] => $727.26 [to] => 208 ) [21] => array ( [from] => 373 [amount] => $2,200.46 [to] => 499 ) [22] => array ( [from] => 194 [amount] => $1,393.01 [to] => 258 ) [23] => array ( [from] => 315 [amount] => $764.34 [to] => 487 ) [24] => array ( [from] => 199 [amount] => $586.14 [to] => 48 ) [25] => array ( [from] => 67 [amount] => $402.24 [to] => 59 ) [26] => array ( [from] => 481 [amount] => $6,551.75 [to] => 400 ) [27] => array ( [from] => 154 [amount] => $1,076.45 [to] => 193 ) [28] => array ( [from] => 431 [amount] => $577.47 [to] => 196 ) [29] => array ( [from] => 408 [amount] => $385.03 [to] => 153 ) [30] => array ( [from] => 240 [amount] => $532.56 [to] => 92 ) [31] => array ( [from] => 195 [amount] => $60.00 [to] => 361 ) [32] => array ( [from] => 425 [amount] => $438.85 [to] => 417 ) [33] => array ( [from] => 309 [amount] => $2,222.94 [to] => 131 ) [34] => array ( [from] => 366 [amount] => $732.07 [to] => 76 ) [35] => array ( [from] => 492 [amount] => $891.88 [to] => 342 ) [36] => array ( [from] => 384 [amount] => $1,936.74 [to] => 414 ) [37] => array ( [from] => 83 [amount] => $270.87 [to] => 427 ) [38] => array ( [from] => 43 [amount] => $1,100.84 [to] => 202 ) [39] => array ( [from] => 428 [amount] => $1,825.57 [to] => 387 ) [40] => array ( [from] => 238 [amount] => $1,059.79 [to] => 381 ) [41] => array ( [from] => 426 [amount] => $416.23 [to] => 97 ) [42] => array ( [from] => 190 [amount] => $7,057.28 [to] => 238 ) [43] => array ( [from] => 229 [amount] => $722.97 [to] => 159 ) [44] => array ( [from] => 129 [amount] => $785.86 [to] => 303 ) [45] => array ( [from] => 44 [amount] => $2,961.07 [to] => 105 ) [46] => array ( [from] => 306 [amount] => $893.92 [to] => 178 ) )
you create $balance array indexed account number. traverse original array in loop.
at each element, can subtract 'amount' $balance indexed 'from' , add 'amount' balance indexed 'to'.
Comments
Post a Comment