unset an array index

Forums ProRealTime English forum ProBuilder support unset an array index

Viewing 5 posts - 1 through 5 (of 5 total)
  • #245370

    hello
    i have an array which contain highs and when break this high, i want to remove this high value from array
    i’m looping through array to draw segments of each value in this array which is highs.
    when break high i want to do like that
    unset($A[i])  or $A[i] = 0 idk …. i need help

    #245374

    Hello,

    you can either :
    * $A[i] = 0 // set previous high in your array to 0 so that you know that this high is no longer relevant. When you need to draw, if the value is 0, then you don’t draw… It is the simplest method.
    * remove that index value by recording all values of the array that come after in previous index, like if you remove a plate from the middle of a pile of plate (the one above replace the removed one, the one above the one above remove the one that was directly above, etc…). That is kind of unset($A[i]) which does not exist in prorealcode.
    => this require more time when the high is broke but will keep your array smaller and thus your code will require less time in a long run…

    Something like that… (I did not tested it)

    2 users thanked author for this post.
    #245399

    when use ARRAYSORT is index change ? for example : i0 = 10 , i1 = 5  , i2= 12 when apply arraysort ascend is i0 = 5 ?

    #245400

    when use arraysort is index change ? for example : i0 = 10 , i1 = 5 , i2 = 12 … when use arraysort ascend, is i0 = 5 ?

    #245402

    Yes, if you use arraysort, it will change data in each index.

    It will not change anything for the code above, as long as you use arraysort outside the while…wend boucle.

    But if you don’t care about the order of the array, you can also use arraysort to accelerate the process of removing the data that are no longer relevant.

    If you want to keep the ability of using the instruction “Iset”, you can use a temporary array to keep only relevant data, then use “unset” to delete the first array and then move back the data in it…

    There is always lot of solutions, the best (fast, shorter, etc) one will depend on what you plan to do with your code…

Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login