title: ColdFusion: How to check if a certain element exists in a 2-dimensional array?
body: <p>I have an 2 dimensional array. I write 3 values into the array during its initialization and i add a fourth value if an array value is not equal with a value passed through a form. Then i want to check, if the fourth value exists.</p>
  
  <p>update.cfm</p>
  
  <pre><code>&lt;cfset array = obj.getArray() /&gt;
  &lt;cfif not StructIsEmpty(form)&gt;
    &lt;cfloop collection="#form#" item="key"&gt;
      &lt;cfif left(key,3) eq "ID_"&gt;
        &lt;cfset number = listLast(key,"_") /&gt;
        &lt;cfset value = evaluate(0,key) /&gt;
        &lt;cfloop index="j" from="1" to="#arrayLen(array)#"&gt;
          &lt;cfif (array[j][1] eq number) and (array[j][3] neq value)&gt;
            &lt;cfset array[j][3] = value /&gt;
            &lt;cfset array[j][4] = "true" /&gt;
          &lt;/cfif&gt;
        &lt;/cfloop&gt;
      &lt;/cfif&gt;
    &lt;/cfloop&gt;
  &lt;cfset obj = createObject("component", "cfc.Obj").init(arg = form.arg, argarray = array) /&gt;
  &lt;cfset application.objDao.update(obj) /&gt;
  </code></pre>
  
  <p>objDao.cfc update method</p>
  
  <pre><code>&lt;cfset matarray = arguments.obj.getArray() /&gt;
    &lt;cfloop index="i" from="1" to="#arrayLen(array)#"&gt;
      &lt;cfquery name="qUpdateAsset" datasource="#variables.instance.dsn#"&gt;
        UPDATE table
        SET value = &lt;cfqueryparam value="#matarray[i][3]#" cfsqltype="cf_sql_integer" /&gt;
  
      &lt;!--- This is wrong, how do i check the existence correctly? ---&gt;
      &lt;cfif StructKeyExists(matarray[i],"4")&gt;
        ,status = 'true'
      &lt;/cfif&gt;
  
        WHERE arg = &lt;cfqueryparam value="#arguments.obj.getArg()#" cfsqltype="cf_sql_smallint" /&gt;
          AND number = &lt;cfqueryparam value="#matarray[i][1]#" cfsqltype="cf_sql_integer" /&gt;
    &lt;/cfquery&gt;
  &lt;/cfloop&gt;
  </code></pre>
  
  <p>My wrong attempt results in this error:</p>
  
  <blockquote>
    <p>You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members. </p>
  </blockquote>