Get specific key from an array

Here is what I put in my Symfony session

$this->session->set('teams', [
  'team_1' => ['MyTeamNameA' => ['player-1' => $safe['team-1-player-1'], 'player-2' => $safe['team-1-player-2'], 'player-3' => $safe['team-1-player-3'], 'player-4' => $safe['team-1-player-4'], 'points' => 0]],
  'team_2' => ['MyTeamNameB' => ['player-1' => $safe['team-2-player-1'], 'player-2' => $safe['team-2-player-2'], 'player-3' => $safe['team-2-player-3'], 'player-4' => $safe['team-2-player-4'], 'points' => 0]],               
]);

And now, in my Twig, I want to retrieve my team_1‘s name, for example, I did this:

app.session.get('teams')['team_1']

It doesn’t work, but, if I do a dump of this last piece of code, I get this result pictured below:
My dump() result in my page

I feel that i’m close to the answer, and yet so far.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *