How to give an echo in the modality? [closed]

-1
Array
(
    [0] => Array
        (
            [Planos] => Array
                (
                    [id] => 57
                    [nome] => test
                    [descricao] => test
                    [valor] => 1.00
                    [status] => 0
                    [id_aluno] => 1
                )

            [Alunos] => Array
                (
                    [id] => 1
                    [nome] => Flávio
                    [telefone] => 155
                    [email] => flavio@flavio
                    [data_nascimento] => 1996-12-08
                    [sexo] => M
                    [endereco] => testando
                    [cpf] => 123
                    [rg] => 123
                )

            [Modalidades] => Array
                (
                    [0] => Array
                        (
                            [id] => 4
                            [modalidade] => MMA
                            [ModalidadesPlano] => Array
                                (
                                    [id] => 1
                                    [id_plano] => 57
                                    [id_modalidade] => 4
                                )

                        )

                    [1] => Array
                        (
                            [id] => 5
                            [modalidade] => Zumba
                            [ModalidadesPlano] => Array
                                (
                                    [id] => 2
                                    [id_plano] => 57
                                    [id_modalidade] => 5
                                )

                        )

                )

        )

)
    
asked by anonymous 28.11.2016 / 19:12

2 answers

4

In your example it would look something like:

$modalidades = $array[0]['modalidades'];

foreach($modalidades as $key => $value){
    echo $value['modalidade'] . "\n";
}

This will print

  

MMA

     

ZUMBA

    
28.11.2016 / 19:18
1

Your question is not very consistent because there are two keys with the name "modality", in addition, you did not specify if you want to print the value or the key, but if your desire is to get the first value of the modalities, where a key modality, would look like this:

$seuArray[0]['Modalidades'][0]['modalidade'];
echo $seuArray;

Example in IDEONE

    
28.11.2016 / 20:15