Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $data = file_get_contents('https://gist.githubusercontent'
- . '.com/jorostoyanov/17b41811d85e9cb81351eecffd81efec/raw/'
- . '473a25c450161a22f0adcba841c230ba9ef83b40/employees.json');
- $data = json_decode($data, true);
- function get_employees_names($data) {
- return array_column($data, 'name');
- }
- function get_salary_range($data) {
- $result = [];
- $result['min'] = $result['max'] = $data[0]['salary'];
- foreach ($data as $employee) {
- if ($employee['salary'] < $result['min']) {
- $result['min'] = $employee['salary'];
- }
- if ($employee['salary'] > $result['max']) {
- $result['max'] = $employee['salary'];
- }
- }
- return $result;
- }
- function get_positions($data) {
- $positions = [];
- foreach ($data as $employee) {
- if (!array_key_exists($employee['position'], $positions)) {
- $positions[$employee['position']] = 1;
- continue;
- }
- $positions[$employee['position']]++;
- }
- return $positions;
- }
- function get_teams($data) {
- $teams = [];
- foreach ($data as $employee) {
- if (!array_key_exists($employee['team'], $teams)) {
- $teams[$employee['team']] = [];
- }
- $teams[$employee['team']][] = [
- 'name' => $employee['name'],
- 'position' => $employee['position'],
- 'salary' => $employee['salary'],
- ];
- }
- return $teams;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement