我需要知道「階段」出現的次數以及是否已完成。元素在多維數組中顯示的次數
的最終目標是要表明:
Phase 1: 50% completed
Phase 2: 0% completed
任務:
Array
(
[0] => Array
(
[phase] => 1
[tasks_status] => completed
)
[1] => Array
(
[phase] => 1
[tasks_status] => pending
)
[2] => Array
(
[phase] => 2
[tasks_status] => pending
)
)
階段:
Array
(
[0] => Array
(
[title] => Briefing e Planejamento
[id] => 1
[created] => 1437436800
)
[1] => Array
(
[title] => Rabiscos e Design
[id] => 2
[created] => 1438128000
)
)
編輯
所以,在你們回答的幫助下,我設法做到了!結果如下:
/** Define wich tasks has been completed **/
foreach ($tasks as $task) {
if ($task['status'] == "completed") {
foreach ($fases as &$fase) {
if ($fase['id'] == $task['fase_id']) {
$fase['numero_total_fases']++;
$fase['completed']++;
}
}
} elseif ($task['status'] == "pending") {
foreach ($fases as &$fase) {
if ($fase['id'] == $task['fase_id']) {
$fase['numero_total_fases']++;
$fase['pending']++;
}
}
} elseif ($task['status'] == "behind schedule") {
foreach ($fases as &$fase) {
if ($fase['id'] == $task['fase_id']) {
$fase['numero_total_fases']++;
$fase['behind schedule']++;
}
}
}
unset($fase);
}
/** Define progress percentage **/
foreach ($fases as &$fase) {
$fase['progresso'] = round(($fase['completed']/($fase['numero_total_fases'])) * 100);
}
/** Print phases progress **/
$f = 1;
foreach ($fases as $fase) {
echo 'Fase '.$f.' - '.$fase['title'].' = '.$fase['progresso'].'% completed';
}
*了一個多小時*因此,有你寫了一些代碼,並試圖東西或做你只是盯着代碼一個小時? – Rizier123
有一點,我嘗試了數十件事,每隔15分鐘左右我就會停下來想想我該怎麼做......只是找不到它 –
然後告訴我們1你的嘗試,我們會幫助你實現它的工作。 – Rizier123