Benutzer:Mediator/arraymultidim

Aus chessmail Wiki
Wechseln zu: Navigation, Suche

handle multi-dimension array


In order to access a 2D array "red;da2021, yellow;fcff00, green;00ff00", we can take the following steps:


1. split the array into an array:

{{#arraydefine:colors|red;da2021, yellow;fcff00, green;00ff00}}

{{#arraydefine:colors|red;da2021, yellow;fcff00, green;00ff00}}

  • colors[0]: {{#arrayindex:colors|0}}
  • colors[1]: {{#arrayindex:colors|1}}
  • colors[2]: {{#arrayindex:colors|2}}
  • size of colors: {{#arraysize:colors}}

2. split the first element into an array


{{#arraydefine:color0|{{#arrayindex:colors|0}}|;}}

{{#arraydefine:color0|{{#arrayindex:colors|0}}|;}}

  • colors[0][0]: {{#arrayindex:color0|0}}
  • colors[0][1]: {{#arrayindex:color0|1}}
  • size of colors[0]: {{#arraysize:color0}}

Note, it is also possible to use variable (require VariablesExtension)


{{#vardefine:i|0}}
{{#arraydefine:color_i|{{#arrayindex:colors|{{#var:i}}}}|;}}

{{#vardefine:i|0}}{{#arraydefine:color_i|{{#arrayindex:colors|{{#var:i}}}}|;}}

  • i=0
  • colors[i][0]: {{#arrayindex:color_i|0}}
  • colors[i][1]: {{#arrayindex:color_i|1}}
  • size of colors[i]: {{#arraysize:color_i}}
Meine Werkzeuge
Namensräume

Varianten
Aktionen
chessmail Wiki
Schachserver
Informationen
Werkzeuge