How To Get Keys of this Array ?

How to Get Key entry in associative array?

what about the other way around and remove an entry form an associative array?

how to Get Key the element with value P in the code below:

:global rot13 ({});
:set ($rot13->“a”) “n”
:set ($rot13->“b”) “o”
:set ($rot13->“c”) “p”

thanks

So simple things are still so crazy in RouterOS.

  1. First approach is like here - http://www.paperstreetonline.com/category/tech/networking/mikrotik/
  2. In the case if known index of element to be removed I prefer use such more simple way (removing element with index $index from array):
:put ([:pick $rot13 0 $index],[:pick $rot13 ($index+1) [:len $rot13]])

I.e. to remove element you construct new array and assign it to the same name:

:set rot13 ([:pick $rot13 0 $index],[:pick $rot13 ($index+1) [:len $rot13]])

Delete by key is much simpler, just write command below to remove element with key “b”:

:set ($rot13->"b")
  1. It is crazy but :find not works with such arrays. You have to use foreach loop and search index or key manually by checking each element.
    Example of iterating through keys/values:
:foreach k,v in=$rot13 do={:put ($k,$v)};

or by index/values:

:for i from=0 to=([:len $rot13]-1) do={:put ($i,[:pick $rot13 $i])};

Thank you very much dear

Very sorry for being late to respond to health conditions

your answer %100
The problem has been resolved

Thank you very much

[quote=devquora post_id=644233 time=1519380870 user_id=115903]
The array_keys() function is used to get all the keys or a subset of the keys of an array.

Here is syntax



array_keys(input_array, search_key_value, strict)
[/quote]

from my testing… this function doesn’t exist within RouterOS. Can you give me a syntax example?

Ironically, the :convert command added in 7.11 that will do the particular conversion in original post.

No array lookup, or any array, needed, at least for the rot13 decrypt…

:put [:convert "c" to=rot13]
# p