Extract item from array (or whatever works)

Hello. Looking for a way to give the “dhcphosts” variable the value, as num, with actual dynamic dhcp clients number on the system, so I can do something like: (if dhcphosts != 0, do something).
“dhcphosts” stores the value as an array as follows, any idea on how to achieve this?. I need to go from being an array to a number for the variable.

#Variable assignment
[MikroTik] > :global dhcphosts do={ip dhcp-server lease print detail count-only where dynamic}
#Check variable value and type
[MikroTik] > $dhcphosts
1
[MikroTik] > :put [$dhcphosts ]
1
;1
[MikroTik] > :typeof [$dhcphosts ]
1
[MikroTik] > :put [:typeof [$dhcphosts ]]
1
array
[MikroTik] > :put [:typeof ($dhcphosts )]
array

You want the number of dynamic dhcp leases? Try this:

:global dhcphosts [ :len [ / ip dhcp-server lease find where dynamic ] ];

eworm, you are a genius, thank you.

Sincerely I prefer to be explicit, if for some reason on future that “dynamic” change behavior…

:global dhcphosts [:len [/ip dhcp-server lease find where dynamic=yes]]

on that way you write a function to count everityme launched the number of dynamic leases

With your method (except for the detail of useless print the number on the terminal) you were almost close to the solution for write directly the value inside a variable:

:global dhcphosts [/ip dhcp-server lease print count-only where dynamic=yes]

and about:
:typeof [$dhcphosts ]
when you call a variable, do not use the !
any results on terminal must be see with :put
you must write like
:put $dhcphosts
:put [:typeof $dhcphosts]