Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:25:50+00:00 2026-06-13T01:25:50+00:00

I have many structures, I’m using StructFindValue() to determine if a a key occurs

  • 0

I have many structures, I’m using StructFindValue() to determine if a a key occurs many times.

I get the expected array returned for “singles”, however I get an empty array for “doubles” and “triples” – this code is actually inside a different code segment, -my is a structure in itself…

If I try ANY of the lines “x= StructFindValue( y, 3, ‘all’ );” in a stand alone template – CF finds the ‘2’ and ‘3’ values just fine – I get an array with the data – but inthe above code – ONLY the values of ‘1’ return anything…

I’m confused.


UPDATE

OK, in response to the request for more information, my server details are:

    Version             ColdFusion 10,282462
    Edition             Developer  
    Operating System    Windows XP  
    Java Version        1.6.0_29   
    OS Version          5.1  
    Update Level        /C:/ColdFusion10/cfusion/lib/updates/chf10000002.jar  
    Adobe Driver Version   4.1 (Build 0001)  

As you can see from the code example below, my array has a few different names, of differing repetitive nature. I want to know which values repeat a specified number of times. As stated above, the structkeyFind() works IF (and only) on the key value of 1. It doesn’t work with the key values of 2, 3 (or 4 or 5 etc, not included here for brevity).

<cfscript>
   _myArry = listToArray('bob,bob,bob,joe,jane,jane,john,john,john,alex,greg');
   _myStats = getDataStats( _myArry );
   writeDump( _myStats );
</cfscript>

<cffunction name="getDataStats">
   <cfargument name="data" required="yes" type="array" >

    <cfscript>
    var _hv = {};

    // default some values
    _hv.vals = {};
    _hv.threes = false;
    _hv.twos = false;
    _hv.ones =false;

    // loop the data put it into separate containers
    for ( var i=1; i LTE arrayLen( arguments.data ); i++ ) {            
        switch ( lcase( arguments.data[i] ) ) {
            case 'bob': // bob 
                if ( structKeyExists( _hv.vals, 'bob' ) ) { _hv.vals.bob = _hv.vals.bob + 1; }
                else { _hv.vals.bob = 1; }
            break;      
            case 'joe': // joe 
                if ( structKeyExists( _hv.vals, 'joe' ) ) { _hv.vals.joe = _hv.vals.joe + 1; }
                else { _hv.vals.joe = 1; }
            break;
            case 'jane': // jane 
                if ( structKeyExists( _hv.vals, 'jane' ) ) { _hv.vals.jane = _hv.vals.jane + 1; }
                else { _hv.vals.jane = 1; }
            break;
            case 'john': // john 
                if ( structKeyExists( _hv.vals, 'john' ) ) { _hv.vals.john = _hv.vals.john + 1; }
                else { _hv.vals.john = 1; }
            break;  
            case 'alex': // alex 
                if ( structKeyExists( _hv.vals, 'alex' ) ) { _hv.vals.alex = _hv.vals.alex + 1; }
                else { _hv.vals.alex = 1; }
            break;  
            case 'greg': // greg 
                if ( structKeyExists( _hv.vals, 'greg' ) ) { _hv.vals.greg = _hv.vals.greg + 1; }
                else { _hv.vals.greg = 1; }
            break;      
        }
    }

    // give me a return struct for testing so i can 'see' where I'm at
    var _thisReturn = {
        'threes' = StructFindValue( _hv.vals, 3, 'all' ),
        'twos' = StructFindValue( _hv.vals, 2, 'all' ),
        'ones' = StructFindValue( _hv.vals, 1, 'all' ),
        'values' = arguments.data
    };
    </cfscript>

    <cfreturn _thisReturn />
</cffunction>

In an attempt to ‘cast’ the values, I have tried each of these variations. However the results are UNCHANGED from the original.

'ones' = StructFindValue( _hv.vals, '1', 'all' ),
'twos' = StructFindValue( _hv.vals, '2', 'all' ),
'threes' = StructFindValue( _hv.vals, '3', 'all' ),

And then

'ones' = StructFindValue( _hv.vals, val( 1 ), 'all' ),
'twos' = StructFindValue( _hv.vals, val( 2 ), 'all' ),
'threes' = StructFindValue( _hv.vals, val( 3 ), 'all' ),
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:25:52+00:00Added an answer on June 13, 2026 at 1:25 am

    The issue here appears to be how CF is storing / displaying / comparing the values.

    Here is a simple demonstration of the problem:

    <cfset Data = 
        { Bob  : 2
        , Joe  : 1+1
        , Jane : "2"
        , John : 2.0
        , Alex : 4/2
        } />
    
    <cfdump var=#Data# />
    
    <cfdump var=#StructFindValue(Data,2,"all")# />
    <cfdump var=#StructFindValue(Data,"2","all")# />
    <cfdump var=#StructFindValue(Data,2.0,"all")# />
    

    The first dump displays all values as 2 except for John who is 2.0

    However, the first two StructFindValue calls both only return Bob,Jane.

    The third StructFindValue call returns Joe,John, Alex.

    This basically demonstrates that CF’s StructFindValue does a very crude comparison for checking equality, and basically isn’t to be trusted when it comes to dealing with numbers.

    (The issue doesn’t exist with Railo, which probably uses the exact same comparison as it would when doing an EQ test, coercing types accordingly. Only tested on CF10,0,0,282462.)

    To solve your problem, it seems you may need to manually walk the struct and replicate the behaviour of StructFindValue yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work a lot with nested data structures, and many times I have to
I need to generate XML structures on the fly using PHP. I've seen many
I'm using adjacency_list< vecS, vecS, bidirectionalS ... > extensively. I have so many graphs
I have multiple calls to many RESTful services. I translate to PHP using native
I have a dynamic array of structures, so I thought I could store the
I have seen many programs consisting of structures like the one below typedef struct
I have a class like this: //Array of Structures class Unit { public: float
I have many static images under a directory in my site structure, and I'm
I have such database structure (1 - one, 0 - many) Product 1->0 Orders
I have many different NSArray 's stored in .dat files, in the Documents folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.