Have to countnumber问题(questions_row_id
)
- evaluator wise和settings wise
array:3 [▼
0 => array:1 [▼
0 => array:3 [▼
"questions_row_id" => 1
"settings_row_id" => 1
"evaluator_row_id" => array:3 [▼
0 => "1"
1 => "4"
2 => "101"
]
]
]
1 => array:1 [▼
0 => array:3 [▼
"questions_row_id" => 2
"settings_row_id" => 1
"evaluator_row_id" => array:2 [▼
0 => "1"
1 => "100"
]
]
]
2 => array:1 [▼
0 => array:3 [▼
"questions_row_id" => 4
"settings_row_id" => 3
"evaluator_row_id" => array:2 [▼
0 => "1"
1 => "101"
]
]
]
]
我在找什么:
For (Evaluator id == 1 and settings id == 1)题数= 2
和
for (Evaluator id == 1 and settings id == 3) number of questions = 1
需要一些关于如何处理这个问题的提示,如果可能的话,也欢迎任何工作样本。
可能是这样的
$evaluators = [];
// start digging
foreach ($myarray as $i1 => $set1) {
// continue digging
foreach ($set1 as $i2 => $set2) {
// each evaluator (1, 4 and 101)
foreach ($set2['evaluator_row_id'] as $evaluator_id) {
// build new array with questions and settings elements
$settings_id = $set2['settings_row_id'];
$evaluators[$evaluator_id][$settings_id][] = $set2['questions_row_id'];
}
}
}
然后根据每个设置ID来计算每个评估者的问题…
$question_counts = [];
foreach ($evaluators as $evaluator_id => $settings_list) {
foreach ($settings_list as $setting_id => $question_ids) {
$question_counts[$evaluator_id][$setting_id] = count($question_ids);
}
}
print_r($question_counts);
输出Array(
[1] => Array(
[1] => 2
[3] => 1
)
[4] => Array(
[1] => 1
)
[101] => Array(
[1] => 1
[3] => 1
)
[100] => Array(
[1] => 1
)
)