0

我有以下数组:

数组$eventos

Array (
    [0] => Array (
            [Evento] => Array (
                    [id] => 1
                    [nome] => Event 1
                )
            [Obreiro] => Array (
                    [0] => Array (
                            [id] => 2
                            [usuario_id] => 4
                            [nome] => Teste
                        )
                    [1] => Array (
                            [id] => 5
                            [usuario_id] => 8
                            [nome] => Teste
                         )
                )
        )
    [1] => Array (
            [Evento] => Array (
                    [id] => 2
                    [nome] => Event 2
                )

            [Obreiro] => Array (
                    [0] => Array (
                            [id] => 3
                            [usuario_id] => 6
                            [nome] => Teste
                        )
                    [1] => Array
                        (
                            [id] => 5
                            [usuario_id] => 7
                            [nome] => Teste
                        )
                )
        )
)

和数组$obreiros

Array (
    [0] => Array (
            [Obreiro] => Array (
                    [id] => 2
                    [usuario_id] => 4
                    [nome] => Foo
                )
        )
    [1] => Array (
            [Obreiro] => Array (
                    [id] => 5
                    [usuario_id] => 8
                    [nome] => Bar
                )
        )
)

我想做:对于每个$obreiros用户,显示是否参与了事件(在 array 中定义$evento[x]['Obreiro'][y],其中 x 和 y 是数字)。

样本:

       | Event 1 | Event 2 | Event n
--------------------------------------
Foo    |    x    |         |    x    
Bar    |    x    |    x    |
Foo 2  |         |         |    x

我怎么能做到这一点?

4

1 回答 1

0

已经完成了代码的工作:

foreach($obreiros as $kObreiro => $obreiro) {
    foreach($eventos as $kEvento => $evento) {
        $faltou = true;

        if(isset($evento['Obreiro']) && is_array($evento['Obreiro']) && count($evento['Obreiro']) > 0) {
            foreach($evento['Obreiro'] as $kEventoObreiro => $eventoObreiro) {
                if($eventoObreiro['usuario_id'] == $obreiro['Usuario']['id']) {
                    $faltou = false;
                }
            }
        }

        if($faltou) {
            echo'X';
        } else {
            echo' ';
        }
    }
    echo '<br />';
}
于 2012-05-09T21:49:56.873 回答