How to give an echo in the sport?

Asked

Viewed 53 times

-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
                                )

                        )

                )

        )

)

2 answers

4

In your example it would be something like:

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

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

This will print

MMA

ZUMBA

1

Your question is not very coherent, because there are two keys with the name "modality", besides, 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 modality, where has a key modality, would be so:

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

Example in IDEONE

Browser other questions tagged

You are not signed in. Login or sign up in order to post.