I can be a bit confused sometimes between arrays and structures. However, I think I understand correctly now that my data below is technically an array of structures (correct me if I'm wrong):
<cfset Contacts = [
{
ID = "1",
CompanyName = "Company One",
FirstName = "Elliott",
LastName = "Smith",
...etc...
},
{
ID = "2",
CompanyName = "Company Two",
FirstName = "Matthew",
LastName = "Ryan",
...etc...
}
]>
I would like to search this data by ID (2, for example) and return the rest of that structure's data (CompanyName, FirstName, LastName, etc...).
How can I do this? (If my data is not in a searchable format, please let me know how I can change it so it is.)
Thank you!
idvalues for a match. That said, if you need to access the elements by a specific key, then storing them in a structure might be better. (Unless you need to maintain a specific order)1,2,...as the keys ie<cfset data = { firstKey = {ID=1, CompanyName="..."}, secondKey ={ID=2, CompanyName="..."} } />. Keep in mind you might store the data differently. For example, store it as JSON - then deserialize it when loaded into CF. Just be aware the file storage approach is not scalable... Out of curiosity, why can't you use a database for this?queryNewto mock up a db query in a pinch. BTW: Feel free to go with Mag's answer.