Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In KRL, how do I detect if a variable is an array or hash?

Tags:

krl

In KRL, I'd like to detect whether a variable is an array or hash so that I know if I need to use the decode or encode operator on it. Is that possible?

I'd like to do something like this:

 my_var = var.is_array => var.decode() | my_var
like image 553
Mike Farmer Avatar asked Jan 28 '26 04:01

Mike Farmer


1 Answers

Update The best way to do this is with the typeof() operator. This is new since the answer, but with the early interpretation of variables, the old way listed in the answer will no longer work.

Another useful operator for examining your data is isnull()

myHash.typeof() => "hash"
myArray.typeof() => "array"
...
like image 171
MEH Avatar answered Feb 01 '26 02:02

MEH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!