Hello everyone! I've just started learning php and I've been doing alot of different tasks to test myself and what I've learned. I'm currently trying to do this exercise and I think I got it sorted, at least most of it but I need your help sorting out of my coding is good, and how to finish the last task
Here is what I need to do:
XXX AS is a company with a number of employees. The company wants a webpage that shows a table of employee data with information regarding their names, gender, date of birth, position, position start date, gross salary, tax amount, pension and amount of net salary.
1: Create your own list of employees and store employee data in an array.
2: Tax amount is based on gross salary amount as following:
less than 100k is tax free
100,000 <200,000 is 10 % tax
200,000 <300,000 is 20%
300,000 <500,000 is 35%
>500,000 is 45%
3: 2.5 % pension is to be decuted from all gross salary
4: Show all momentary amounts with the two decimal places and thousand separators.
This is what I've done so far:
<?php /*****GROSS SALARY***** Creates the variabel containing the gross salary data for each employee*/ /*Aron*/ $gross_salary1 = 635000.00; /*Britney*/ $gross_salary2 = 420000.00; /*Daniel*/ $gross_salary3 = 260000.00; /*Jessica*/ $gross_salary4 = 350000.00; /*Peter*/ $gross_salary5 = 250000.00; /*Keith*/ $gross_salary6 = 90000.00; /*****PENSION***** Creates the variabel to deduct pension*/ $pension = 0.025; /*****TAXATION***** /* Creates if statements that runs trough the salaries and deducts tax rate accordingly for each employee*/ /* Aron and taxes*/ if ($gross_salary1 >= 500000) { $tax1=0.45; } if ($gross_salary1 >= 300000 and $gross_salary1 < 500000) { $tax1=0.35; } if ($gross_salary1 >= 200000 and $gross_salary1 < 300000) { $tax1=0.2; } if ($gross_salary1 >= 100000 and $gross_salary1 < 200000) { $tax1=0.1; } if ($gross_salary1 < 100000) { $tax1=0; } /* Britney and taxes*/ if ($gross_salary2 >= 500000) { $tax2=0.45; } if ($gross_salary2 >= 300000 and $gross_salary2 < 500000) { $tax2=0.35; } if ($gross_salary2 >= 200000 and $gross_salary2 < 300000) { $tax2=0.2; } if ($gross_salary2 >= 100000 and $gross_salary2 < 200000) { $tax2=0.1; } if ($gross_salary2 < 100000) { $tax2=0; } /* Daniel and taxes*/ if ($gross_salary3 >= 500000) { $tax3=0.45; } if ($gross_salary3 >= 300000 and $gross_salary3 < 500000) { $tax3=0.35; } if ($gross_salary3 >= 200000 and $gross_salary3 < 300000) { $tax3=0.2; } if ($gross_salary3 >= 100000 and $gross_salary3 < 200000) { $tax3=0.1; } if ($gross_salary3 < 100000) { $tax3=0; } /* Jessica and taxes*/ if ($gross_salary4 >= 500000) { $tax4=0.45; } if ($gross_salary4 >= 300000 and $gross_salary4 < 500000) { $tax4=0.35; } if ($gross_salary4 >= 200000 and $gross_salary4 < 300000) { $tax4=0.2; } if ($gross_salary4 >= 100000 and $gross_salary4 < 200000) { $tax4=0.1; } if ($gross_salary4 < 100000) { $tax4=0; } /* Peter and taxes*/ if ($gross_salary5 >= 500000) { $tax5=0.45; } if ($gross_salary5 >= 300000 and $gross_salary5 < 500000) { $tax5=0.35; } if ($gross_salary5 >= 200000 and $gross_salary5 < 300000) { $tax5=0.2; } if ($gross_salary5 >= 100000 and $gross_salary5 < 200000) { $tax5=0.1; } if ($gross_salary5 < 100000) { $tax5=0; } /* Keitd and taxes*/ if ($gross_salary6 >= 500000) { $tax6=0.45; } if ($gross_salary6 >= 300000 and $gross_salary6 < 500000) { $tax6=0.35; } if ($gross_salary6 >= 200000 and $gross_salary6 < 300000) { $tax6=0.2; } if ($gross_salary6 >= 100000 and $gross_salary6 < 200000) { $tax6=0.1; } if ($gross_salary6 < 100000) { $tax6=0; } /*****ABC ARRAY***** /*Sorts all the employees in a multiarray, and also does the tax-pension-salary*/ $abc = array( 'e_1'=>array ('Aron','M','1930/01/25','Manager','1998/01/01',number_format($gross_salary1,2,".",","),number_format($gross_salary1*$tax1,2,".",","),number_format($gross_salary1*$pension,2,".",","),number_format($gross_salary1-$gross_salary1*$pension-$gross_salary1*$tax1,2,".",",")), 'e_2'=>array ('Britney','F','2001/05/06','Researcher','2001/03/15',number_format($gross_salary2,2,".",","),number_format($gross_salary2*$tax2,2,".",","),number_format($gross_salary2*$pension,2,".",","),number_format($gross_salary2-$gross_salary2*$pension-$gross_salary2*$tax2,2,".",",")), 'e_3'=>array ('Daniel','M','2003/01/15','Officer','2003/12/06',number_format($gross_salary3,2,".",","),number_format($gross_salary3*$tax3,2,".",","),number_format($gross_salary3*$pension,2,".",","),number_format($gross_salary3-$gross_salary3*$pension-$gross_salary3*$tax3,2,".",",")), 'e_4'=>array ('Jessica','F','2002/11/21','Officer','2007/02/20',number_format($gross_salary4,2,".",","),number_format($gross_salary4*$tax4,2,".",","),number_format($gross_salary4*$pension,2,".",","),number_format($gross_salary4-$gross_salary4*$pension-$gross_salary4*$tax4,2,".",",")), 'e_5'=>array ('Peter','M','1998/01/07','Assisant','2009/09/06',number_format($gross_salary5,2,".",","),number_format($gross_salary5*$tax5,2,".",","),number_format($gross_salary5*$pension,2,".",","),number_format($gross_salary5-$gross_salary5*$pension-$gross_salary5*$tax5,2,".",",")), 'e_6'=>array ('Keitd','M','2003/07/25','Intern','2012/06/27',number_format($gross_salary6,2,".",","),number_format($gross_salary6*$tax6,2,".",","),number_format($gross_salary6*$pension,2,".",","),number_format($gross_salary6-$gross_salary6*$pension-$gross_salary6*$tax6,2,".",","))); /*Sorts the employee array by the names of the employees by default when loading the page*/ array_multisort($abc,SORT_ASC); /*****TABLE&SUCH****** /*defines the border scale */ echo '<table border="7">'; /*Prints out a table witd all the information headlines regarding the table and its employees*/ echo '<tr><td><center><strong><big>','Name','</strong></big></center></td>' .'<td><center><strong><big>', 'Gender','</strong></big></center></td>' .'<td><center><strong><big>', 'DOB','</strong></big></center></td>' .'<td><center><strong><big>', 'Position','</center></strong></big></td>' .'<td><center><strong><big>', 'Start Date','</strong></big></center></td>' .'<td><strong><big>','Gross Salary','</strong></big></td>' .'<td><center><strong><big>', 'Tax','</center></strong></big></td>' .'<td><center><strong><big>', 'Pension','</center></strong></big></td>' .'<td><center><strong><big>', 'Net Salary','</strong></big></center></td>'; /*Puts the data of the employees into the table*/ foreach ($abc as $abct) { echo '<tr><td><div align="left">', $abct[0],'</div></td>' .'<td><center>', $abct[1],'</center></td>' .'<td><center>', $abct[2],'</center></td>' .'<td><div align="left">', $abct[3],'</div></td>' .'<td><center>', $abct[4],'</center></td>' .'<td><div align="right">', $abct[5],'</div></td>' .'<td><div align="right">', $abct[6],'</div></td>' .'<td><div align="right">', $abct[7],'</div></td>' .'<td><div align="right">', $abct[8],'</div></td>' . '</tr>'; } echo '</table>';/*Ends the table*/ ?>
Any help on sorting the code better would be appreciated Again I'm not the best..
AND I would love help with the last task which is:
5: The page should show the listing of the data in a sorted order depending on a selected sort field and sort order (ascending and descending). The default sorting should be by name.
Thanks guys you're awsome <3