Search code examples
coldfusion

doing something wrong in pointing the values in a structure


I have this gist code do i need to use a struct to append the values, not sure what is going on in here

<cfscript>
ex = {};
s = '8734568';
k = 'MyStr';
writedump(ex[s][k]);
</cfscript>

what i am doing wrong in here, do i need to wrap it with string, i tried but not working

tried like this

writedump(ex['#s#']['#k#']);

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


Solution

  • You are trying to access elements of the struct that do not yet exists. You have to set them first. For example...

    <cfscript>
    ex = {};
    s = '8734568';
    k = 'MyStr';
    ex[s] = k;
    writedump(ex);
    </cfscript>