元素在多维数组中显示的次数

I need to know how many times a "phase" shows up, and if it's completed or not.

The final objective is to show:

Phase 1: 50% completed
Phase 2: 0% completed

Tasks:

Array
(
    [0] => Array
        (
            [phase] => 1
            [tasks_status] => completed
        )

    [1] => Array
        (
            [phase] => 1
            [tasks_status] => pending
        )
    [2] => Array
        (
            [phase] => 2
            [tasks_status] => pending
        )
)

Phases:

Array
(
    [0] => Array
        (
            [title] => Briefing e Planejamento
            [id] => 1
            [created] => 1437436800
        )

    [1] => Array
        (
            [title] => Rabiscos e Design
            [id] => 2
            [created] => 1438128000
        )

)

edit

So, with the help of you guys who answered, I've managed to do it! Here's the result:

            /** 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';
            }

A little slow to the draw, but since I already wrote it, here's my answer too. It's always helpful to see that most programming tasks can be done several ways:

<?php 
  $tasks = array(
    array(
      'phase' => 1,
      'tasks_status' => 'completed'
    ),
    array(
      'phase' => 1,
      'tasks_status' => 'pending'
    ),
    array(
      'phase' => 2,
      'tasks_status' => 'pending'
    )
  );
  //$phases = array();
  $phases = array(
    1=>array(
      'title'=>'Briefing e Planejamento',
      'id'=>1,
      'created'=>1437436800
    ),
    2=>array(
      'title'=>'Rabiscos e Design',
      'id'=>2,
      'created'=>1438128000
    )
  );

  foreach($tasks as $key=>$task){
    if(isset($phases[$task['phase']])){
      $thisPhase = $phases[$task['phase']];
    }
    else{
      $thisPhase = array(
        'completed' => 0,
        'pending' => 0
      );
    }
    $thisPhase[$task['tasks_status']]++;
    $phases[$task['phase']] = $thisPhase;
  }

  foreach($phases as $name=>$phase){
    echo $phase['title'].": ".round(($phase['completed'] / ($phase['completed'] + $phase['pending'])) * 100)."% completed <br>";
  }
?>

I know you've already finished, but regarding the phases array - you should have put that in the original question if you wanted it worked into the answer. My suggestion, however, would be to use the ID of the phase as the index name in your phases array. The solution I posted will work with that too - and you can then use $phase in the final foreach loop to show the title or created time.

Is this what you are after?

I assume you want to calculate the percentage based on your original array.

<?php

$tasks = array(
    array(
        'phase' => 1,
        'tasks_status' => 'completed'
    ),
    array(
        'phase' => 1,
        'tasks_status' => 'pending'
    ),
    array(
        'phase' => 2,
        'tasks_status' => 'pending'
    ),
);

$phases_arr = array();
foreach($tasks as $task) {
    if(!array_key_exists($task['phase'], $phases_arr)) {
        $phases_arr[$task['phase']] = array();
    }
    $phases_arr[$task['phase']][] = $task;
}

$phases = array();

foreach($phases_arr as $phase_num => $phase) {
    $p = array(
        'phase' => $phase_num,
        'total' => count($phase),
        'complete' => 0,
        'percent' => 0
    );

    foreach($phase as $task) {
        if($task['complete']) $p['complete']++;
    }

    $p['percent'] = ($p['complete'] / $p['total']) * 100;
    $phases[$phase_num] = $p;
}

foreach($phases as $phase) {
    echo "<p>Phase {$phase['phase']}: {$phase['percent']}% completed</p>";
}

Your inputs,

$tasks = array( array('phase' => 1, 'tasks_status' => 'completed'),
                array('phase' => 1, 'tasks_status' => 'pending'),
                array('phase' => 2, 'tasks_status' => 'pending'),
          );

Consider this,

$phase = array();

foreach ($tasks as $key => $value)
{
    $phase[$value['phase']][] = $value['tasks_status'] == 'completed' ? 50 : 0 ;
}

function get_phase_percentage($i)
{
    global $phase;
    if(isset($phase[$i]) && is_array($phase[$i]))
        return array_sum($phase[$i]);
    return 0;
}

Use it like,

Phase 1: <?php echo get_phase_percentage(1)?>% completed
Phase 2: <?php echo get_phase_percentage(2)?>% completed