Search code examples
coldfusion

coldfusion if - how to look for several items in an IF


I have an if structure as follows:

<cfif #user.personnel_no# is 'xxxxx' or #user.personnel_no# is 'xxxxx' or #user.personnel_no# is 'xxxxx'>
---data
</cfif>

how can I do something like:

<cfif #user.personnel_no# in ('xxxxx','yyyyy','zzzzz')>
---data
</cfif>

to look among all values in if?

or declaring a list and do something like

list = 'xxxxx','yyyyy','zzzzz'

<cfif #user.personnel_no# in list>
    ---data
</cfif>

Thank you.


Solution

  • <cfscript>
    user.personnel_no = 'yyyyy' 
    
    asArray = ['xxxxx','yyyyy','zzzzz']
    writeOutput(asArray.find(user.personnel_no)) // 2
    
    
    asList = 'xxxxx,yyyyy,zzzzz'
    writeOutput(asList.listfind(user.personnel_no)) // 2
    
    </cfscript>
    

    https://trycf.com/gist/f737ef6d010d4ce37936f1d53d021a62/lucee5?theme=monokai

    https://cfdocs.org/listfind

    https://cfdocs.org/arrayfind