Предполагается, что у вас есть $employees
многомерный массив;ниже приведен код, который дает вам зарплату и ее масштаб, если он высокий, низкий или хороший.
Вот код;
/**
* Function to calculate salary scale is high, good, low
* @param int $salary
* @return string
*/
function calculateSalaryScale($salary) {
if ($salary >= 3000) {
$scale = "High paying";
} else if (2000 <= $salary && $salary <= 2999 ) {
$scale = "Good paying";
} else {
$scale = "Low paying";
}
return $scale;
}
// Assuming your employyees array is like below
$employees = array(
array('emp_id' => 1, 'name' => 'John Doe', 'wage' => 90, 'hrs'=> 8),
array('emp_id' => 2, 'name' => 'Lorem Ipsum', 'wage' => 150, 'hrs'=> 6),
array('emp_id' => 3, 'name' => 'Doler amit', 'wage' => 50, 'hrs'=> 10),
);
foreach ($employees as &$employee) {
$employee['salary'] = $employee['wage'] * $employee['hrs'] * 4;
$employee['scale'] = calculateSalaryScale($employee['salary']);
}
echo "<pre>";
print_r($employees);
exit;
Это даст вам вывод ниже;
Array
(
[0] => Array
(
[emp_id] => 1
[name] => John Doe
[wage] => 90
[hrs] => 8
[salary] => 2880
[scale] => Good paying
)
[1] => Array
(
[emp_id] => 2
[name] => Lorem Ipsum
[wage] => 150
[hrs] => 6
[salary] => 3600
[scale] => High paying
)
[2] => Array
(
[emp_id] => 3
[name] => Doler amit
[wage] => 50
[hrs] => 10
[salary] => 2000
[scale] => Good paying
)
)
Затем вы можете продолжить работу с массивом $employees
соответственно.