How can you check if two arrays are the same using CFML?

Using CFML (ColdFusion Markup Langauge, aka ColdFusion), how can you compare if two one-dimensional arrays are the same?

+3
source share
7 answers

Assuming all values ​​in the array are simple values, it is easiest to convert arrays to lists and just compare strings.

<cfif arrayToList(arrayA) IS arrayToList(arrayB)>
    Arrays are equal!
</cfif>

Not as elegant as the other solutions proposed, but they are simple.

+1
source

CFML, java. Adobe (http://coldfused.blogspot.com/), ColdFusion java- (java.util.List). , Java CFML.

, 2 , , , equals. , , .

<cfset array1 = listToArray("tom,dick,harry,phred")/>
<cfset array2 = listToArray("dick,harry,phred") />
<cfset array3 = listToArray("tom,dick,harry,phred")/>

<cfoutput>
Array2 equals Array1 #array2.equals(array1)# (returns a NO) <br/>
Array3 equals Array1 #array3.equals(array1)# (returns a YES) <br/>
</cfoutput>
+11

, , JSON WDDX. , . , , ( / ).

<cfsilent>
    <!--- create some semi-complex test data --->
    <cfset data = StructNew() />
    <cfloop from="1" to="50" index="i">
        <cfif variables.i mod 2 eq 0>
            <cfset variables.data[variables.i] = StructNew()/>
            <cfset tmp = variables.data[variables.i] />
            <cfloop from="1" to="#variables.i#" index="j">
                <cfset variables.tmp[variables.j] = 1 - variables.j />
            </cfloop>
        <cfelseif variables.i mod 3 eq 0>
            <cfset variables.data[variables.i] = ArrayNew(1)/>
            <cfset tmp = variables.data[variables.i] />
            <cfloop from="1" to="#variables.i#" index="j">
                <cfset variables.tmp[variables.j] = variables.j mod 6 />
            </cfloop>
            <cfset variables.data[variables.i] = variables.tmp />
        <cfelse>
            <cfset variables.data[variables.i] = variables.i />
        </cfif>
    </cfloop>
</cfsilent>

<cftimer label="JSON" type="inline">
    <cfset jsonData = serializeJson(variables.data) />
    <cfset jsonHash = hash(variables.jsonData) />
    <cfoutput>
        JSON: done.<br />
        len=#len(variables.jsonData)#<br/>
        hash=#variables.jsonHash#<br />
    </cfoutput>
</cftimer>
<br/><br/>
<cftimer label="WDDX" type="inline">
    <cfwddx action="cfml2wddx" input="#variables.data#" output="wddx" />
    <cfset wddxHash = hash(variables.wddx) />
    <cfoutput>
        WDDX: done.<br />
        len=#len(variables.wddx)#<br/>
        hash=#variables.wddxHash#<br />
    </cfoutput>
</cftimer>

, :

JSON: done.
len=7460
hash=5D0DC87FDF68ACA4F74F742528545B12
JSON: 0ms

WDDX: done.
len=33438
hash=94D9B792546A4B1F2FAF9C04FE6A00E1
WDDX: 47ms

, , , . JSON WDDX.

, compareAnything , JSON WDDX.

+3

Jasons, , , -, , - , WDDX.

, , CFML. , , ...

Edit: Adams ( ) - JSON , . CFMX 6.1, JSON, .

+2

Java- CF , , .

ColdFusion- java- (java.util.List). , Array. CF Array, java-, CF.

  • 1, , 2
  • 1 2

: http://coldfused.blogspot.com/2007/01/extend-cf-native-objects-harnessing.html

, , , Java Array , , .

http://www.barneyb.com/barneyblog/2008/05/08/use-coldfusion-use-java/

, , Java , , CF.

+2

, . , . , native CF, - - , .

, CF, Java . .

, , ,   ( false)   1 len , false, .

.

+1

Source: https://habr.com/ru/post/1696553/


All Articles