From 2b77e5eafc3474597635b1f860f1a61a4f34df3e Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Fri, 23 Dec 2022 09:34:38 -0600 Subject: [PATCH] - Add function to calculate vault balances - Modify split function to return a single user --- functions.php | 17 ++++++++++++++--- index.php | 5 +++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index d9063aa..9ce528f 100644 --- a/functions.php +++ b/functions.php @@ -158,17 +158,28 @@ function vaultTxns($csv) { // splitVault(): split CSV array into two separate arrays based on the user function splitVault($csv, $field, $user): array { - $usr1Vault = []; + $usrVault = []; $usr2Vault = []; foreach ($csv as $entry) { if (isset($entry[$field]) && $entry[$field] == $user) { $usr1Vault[] = $entry; } else { - $usr2Vault[] = $entry; + continue; } } - return [$usr1Vault, $usr2Vault]; + return $usr1Vault; +} + +// Calculate user balances +function userBalance($array, $field) { + $total = 0; + + foreach ($array as $item) { + $total += $item[$field]; + } + + return $total; } ?> \ No newline at end of file diff --git a/index.php b/index.php index f597663..c6587b9 100644 --- a/index.php +++ b/index.php @@ -26,10 +26,11 @@

Balances

'; - print_r($result); + print_r($usr1Vault); echo ''; ?>