# Increment Array Element

**URL:** <https://community.f5.com/t/increment-array-element/42678>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [September 19, 2012, 12:50pm UTC](https://community.f5.com/t/increment-array-element/42678 "2012-09-19T12:50:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ger\_Hackett\_323](https://avatars.discourse-cdn.com/v4/letter/g/94ad74/32.png) [@Ger\_Hackett\_323](https://community.f5.com/u/Ger_Hackett_323)\
**Post date:** [September 19, 2012, 12:50pm UTC](https://community.f5.com/t/increment-array-element/42678/1 "2012-09-19T12:50:45Z")

</div>

Hi,

Is there any neat way to increment any array element. At the moment I’m doing:

set TempVar $::MyArray($some\_index)

incr TempVar

set ::MyArray($some\_index) $TempVar

unset TempVar

Thanks,

Ger.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [September 19, 2012, 1:08pm UTC](https://community.f5.com/t/increment-array-element/42678/2 "2012-09-19T13:08:20Z")

</div>

You could potentially one-line it with something like this:

array set TempVar { var 1 }

set TempVar [incr TempVar(var)]

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [September 19, 2012, 1:09pm UTC](https://community.f5.com/t/increment-array-element/42678/3 "2012-09-19T13:09:01Z")

</div>

You could potentially one-line it with something like this:

array set TempVar { var 1 }

set TempVar(var) [incr TempVar(var)]

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [September 20, 2012, 2:03pm UTC](https://community.f5.com/t/increment-array-element/42678/4 "2012-09-20T14:03:16Z")

</div>

Using a global array will disable CMP. You might want to check if using a table will work for your scenario as it’s CMP compatible:

> **[DevCentral](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

> **[DevCentral](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

Aaron
