Lua:
function isInArray(arr,val,checkindex) --By Mock the bear (MTB)
assert(type(arr)=='table','#1 must be a table')
for i,b in pairs(arr) do
if (checkindex and i == val) or (not checkindex and b == val) then
return true, checkindex and b or i
end
end
return false
end
The old isInArray return only true. This function return false and the value from table.
You can use like this:
Code:
local tabl = {"hi","My","Name",4,"is","mock",lol="mock"}
local dat,find = isInArray(tabl,'mock')
if dat then print("The index form the find is:"..find) end
---- Or
local dat,find = isInArray(tabl,8,true)
if not dat then
print('There is no index 8')
end
local dat,find = isInArray(tabl,'lol',true)
if dat then
print('the index lol get a value:'..find)
end
The index form the find is:6
There is no index 8
the index lol get a value:mock
Last edited: