KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: The command "Find in array" with a two-dimensional array
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: January 24, 2003

Compatibility: Version 6.7.x and 6.8.x

The command Find in array returns the number of the first element in an array that matches the value. While this is simple to do with a one dimensional array, this isn't as straightforward a process with a two-dimensional array.

Find in array (array; value{; start}) ->Number


Normally to find "abc" in the array "Myarray" you would write something like:
Find in array(Myarray;"abc")

For a two-dimensional array, this would fail.

Let's take for example the following two-dimensional array:

Array Text(Myarray;2;2)
Myarray{1}{1}:="a1"
Myarray{1}{2}:="a2"
Myarray{2}{1}:="b1"
Myarray{2}{2}:="b2"

To find "a2", you would need to do something like

$find:=Find in array(Myarray{1};"a2")
$find1:=Find in array(Myarray{2};"a2")
$find would equal to 2
$find1 would equal -1

If you have a large two-dimensional array, you can build a "For" loop:

$arrSize:=Size of array(Myarray)
For ($i;1;$arrSize)
 $find:=Find in array(Myarray{$i};"a2")
  If ($find>0)
   `do something
 End if
End for