<?php
$data = [
[
'question_category' => 'Engagement',
'result' => '6.6667',
'employee_first_name' => 'Person A',
],
[
'question_category' => 'Tenure',
'result' => '7.6667',
'employee_first_name' => 'Person A',
],
[
'question_category' => 'Engagement',
'result' => '7.6667',
'employee_first_name' => 'Person B',
],
[
'question_category' => 'Tenure',
'result' => '8.3333',
'employee_first_name' => 'Person B',
],
];
$grouped = [];
foreach($data as $row){
// I think this is the mapping? If anything else exists,
// this will throw
$xOrY = match($row['question_category']){
'Engagement' => 'x',
'Tenure' => 'y',
};
// Group by name
$grouped[$row['employee_first_name']][$xOrY] = $row['result'];
}
// Remove the names (optional)
$grouped = array_values($grouped);
var_dump($grouped);
- Output for 8.1.23 - 8.1.33, 8.2.7 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array(2) {
[0]=>
array(2) {
["x"]=>
string(6) "6.6667"
["y"]=>
string(6) "7.6667"
}
[1]=>
array(2) {
["x"]=>
string(6) "7.6667"
["y"]=>
string(6) "8.3333"
}
}
preferences:
70.34 ms | 406 KiB | 5 Q