Get value in Array Chunk

Asked

Viewed 54 times

0

I have 12 teams registered in a table and I want to divide them into 3 groups. So I receive these teams in array form and use the array_chunk to divide them, which will form the 3 groups of 4 teams I want.

But I’m having trouble accessing NAME_TEAM, I’ve tried several ways and I can’t. Someone could help me?

See how the array is mounted.

Array
(
    [0] => Array
        (
            [0] => stdClass Object
                (
                    [id_t] => 222
                    [name_team] => Atletico GO
                    [name_coach] => Afonso de Carvalo
                    [active_team] => 1
                )

            [1] => stdClass Object
                (
                    [id_t] => 223
                    [name_team] => Atletico MG
                    [name_coach] => Levir culpi
                    [active_team] => 1
                )

            [2] => stdClass Object
                (
                    [id_t] => 224
                    [name_team] => Palmeiras
                    [name_coach] => Cuca
                    [active_team] => 1
                )

            [3] => stdClass Object
                (
                    [id_t] => 225
                    [name_team] => Flamengo
                    [name_coach] => Zé Ricardo
                    [active_team] => 1
                )

        )

    [1] => Array
        (
            [0] => stdClass Object
                (
                    [id_t] => 226
                    [name_team] => Corinthians
                    [name_coach] => José da Silva
                    [active_team] => 1
                )

            [1] => stdClass Object
                (
                    [id_t] => 227
                    [name_team] => Santos
                    [name_coach] => Dorival Junior
                    [active_team] => 1
                )

            [2] => stdClass Object
                (
                    [id_t] => 228
                    [name_team] => Grêmio
                    [name_coach] => Renato Portallupi
                    [active_team] => 1
                )

            [3] => stdClass Object
                (
                    [id_t] => 229
                    [name_team] => Ponte Preta
                    [name_coach] => Ernando
                    [active_team] => 1
                )

        )

    [2] => Array
        (
            [0] => stdClass Object
                (
                    [id_t] => 242
                    [name_team] => Vasco
                    [name_coach] => Milton Santos
                    [active_team] => 1
                )

            [1] => stdClass Object
                (
                    [id_t] => 245
                    [name_team] => Botafogo
                    [name_coach] => Jair Ventura
                    [active_team] => 1
                )

            [2] => stdClass Object
                (
                    [id_t] => 246
                    [name_team] => São Paulo
                    [name_coach] => Rogério Ceni
                    [active_team] => 1
                )

            [3] => stdClass Object
                (
                    [id_t] => 247
                    [name_team] => Cruzeiro
                    [name_coach] => Mano Menezes
                    [active_team] => 1
                )

        )

)
  • How did you try to access it? could you put the code

  • I am using it and it is printing just a few: $array = array_chunk( $Teams, 4 ); $f = 0; foreach ( $array as $team ) { echo $[$f]->name_team; $f++ }

  • managed like this: $f = 0; foreach ( $array as $team ) { for ($i=0; $i < 4 ; $i++) { echo $team[$f][$i]->name_team; } $f++ ;}

  • thanks for your attention

1 answer

0

Tries:

$obj = $teuArray[0][0];

$nomeTime = $obj->name_team;
  • tried the way it said and didn’t work, I’m trying this and took some: $array = array_chunk( $Teams, 4 ); $f = 0; foreach ( $array as $team ) { echo $team[$f]->name_team; $f++ }

  • managed like this: $f = 0; foreach ( $array as $team ) { for ($i=0; $i < 4 ; $i++) { echo $team[$f][$i]->name_team; } $f++ ;}

  • thanks for your attention

  • Anytime, buddy. If the post helped vote for it there. D

Browser other questions tagged

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