Last active
November 9, 2019 11:33
-
-
Save debonx/81690b70e16924a3f83edb064fa6d93b to your computer and use it in GitHub Desktop.
Play with php built-in array_sum(), array_map(), array_filter() to calculate yearly savings from arbitrary taxes and income.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$annualExpenses = [ | |
"vacations" => 1000, | |
"carRepairs" => 1000, | |
]; | |
$monthlyExpenses = [ | |
"rent" => 1500, | |
"utilities" => 200, | |
"healthInsurance" => 200 | |
]; | |
$weeklyExpenses = [ | |
"gas" => 25, | |
"food" => 90, | |
"entertainment" => 47 | |
]; | |
$grossSalary = 48150; | |
$socialSecurity = $grossSalary * .062; | |
$incomeSegments = [[9700, .88], [29775, .78], [8675, .76]]; | |
$netIncome = array_sum(array_map(function($array){ | |
return $array[0] * $array[1]; | |
}, $incomeSegments)); | |
$netIncome -= $socialSecurity; | |
$annualIncome = $netIncome; | |
echo "Annual income before deducting annual expenses:\n$annualIncome\n"; | |
$annualIncome -= array_sum($annualExpenses); | |
echo "Annual income after deducting annual expenses:\n$annualIncome\n"; | |
$monthlyIncome = $annualIncome/12; | |
echo "\nMonthly income before deducting monthly expenses:\n$monthlyIncome\n"; | |
$monthlyIncome -= array_sum($monthlyExpenses); | |
echo "\nMonthly income after calculation:\n$monthlyIncome \n"; | |
$weeklyIncome = $monthlyIncome/4.33; | |
echo "\nWeekly income before calculation:\n$weeklyIncome\n"; | |
$weeklyIncome -= array_sum($weeklyExpenses); | |
echo "\nWeekly income after calculation:\n$weeklyIncome\n"; | |
$leftoverMoney = $weeklyIncome * 52; | |
echo "\nRemaining income: $leftoverMoney"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment