<?php define('TAX_RATES', [ 'Single' => [ 'Ranges' => [0, 9700, 39475, 84200, 160725, 204100, 510300], 'MinTax' => [0, 970, 4543, 14382, 32748, 46628, 153798], 'Rates' => [10, 12, 22, 24, 32, 35, 37], ], 'Married_Jointly' => [ 'Ranges' => [0, 19400, 78950, 168400, 321450, 408200, 612350], 'MinTax' => [0, 1940, 9086, 28765, 65497, 93257, 164709], 'Rates' => [10, 12, 22, 24, 32, 35, 37], ], 'Married_Separately' => [ 'Ranges' => [0, 9700, 39475, 84200, 160725, 204100, 306175], 'MinTax' => [0, 970, 4543, 14382.50, 32748.50, 46628.50, 82354.75], 'Rates' => [10, 12, 22, 24, 32, 35, 37], ], 'Head_Household' => [ 'Ranges' => [0, 13850, 52850, 84200, 160700, 204100, 510300], 'MinTax' => [0, 1385, 6065, 12962, 31322, 45210, 152380], 'Rates' => [10, 12, 22, 24, 32, 35, 37], ] ]); $tableTemplate = <<<TABLE <h2>%s</h2> <table border="1"> <tr> <th>Taxable Income</th> <th>Tax Rate</th> </tr> %s </table> TABLE; $rowTemplate = <<<ROW <tr> <td>%s</td> <td>%s%d%%</td> </tr> ROW; foreach (TAX_RATES as $status => $data) { $rows = []; $count = count($data['Rates']); for ($i = 0; $i < $count; ++$i) { $rows[] = sprintf( $rowTemplate, isset($data['Ranges'][$i + 1]) ? '$' . number_format($data['Ranges'][$i] + ($i ? 1 : 0)) . ' - $' . number_format($data['Ranges'][$i + 1]) : "> $" . number_format($data['Ranges'][$i]), $data['MinTax'][$i] ? '$' . number_format($data['MinTax'][$i], 2) . ' + ' : '', $data['Rates'][$i] ); } printf($tableTemplate, $status, implode("\n", $rows)); }
You have javascript disabled. You will not be able to edit any code.