XF 2.0 xf:foreach loop through multidimensional array

Finexes

Well-known member
Hello guys,

I am using GameQ to query my gameservers. I passed the results as variable to my template and could successfully display the servername, IP, etc.
Now I would like to display the players connected to each server, but it is passed as a multidimensional array.

Example:
Code:
array [
  "ts3" => array [
    "players" => array [
      0 => array [
        "gq_name" => "Player 1"
      ]
      1 => array [
        "gq_name" => "Player 2"
      ]
    ]
  ]
  "cod4" => array [
    "players" => array [
      0 => array [
        "gq_name" => "Player 1"
      ]
      1 => array [
        "gq_name" => "Player 2"
      ]
    ]
  ]
  "ins" => array [
    "players" => array [
      0 => array [
        "gq_name" => "Player 1"
      ]
      1 => array [
        "gq_name" => "Player 2"
      ]
    ]
  ]
]

Is it possible with <xf:foreach> to display the players per server?
 
You'd nest the foreach blocks:

HTML:
<xf:foreach loop="$servers" key="$serverId" value="$server">
     Server: {$serverId}
    <xf:foreach loop="$server.players" value="$player">
        Player name: {$player.gq_name}
    </xf:foreach>
</xf:foreach>

Obviously, you'd need to add the relevant HTML markup :)

Liam
 
Back
Top Bottom