I have an array that outputs these values:
Array (
[0] => stdClass Object (
[ID] => 6585
[COLOR] => red
[Name] => steve
)
[1] => stdClass Object (
[ID] => 5476
[COLOR] => blue
[Name] => sol
)
[2] => stdClass Object (
[ID] => 7564
[COLOR] => yellow
[Name] => jake
)
[3] => stdClass Object (
[ID] => 3465
[COLOR] => green
[Name] => helen
)
)
Now, I will know the ID of the person, and I need the get the COLOR value for that specific value set. How is this best achieved please?
Something like this:
Use like
echo getColorById($arr, 3465);EDIT:
The way you have the data leads to slowing down access times. A better suggestion is to (since it seems
IDis unique), you’d rather have that as the key to your array. You have integer indices to it, now. Construct the array (unless you are receiving it from some area beyond what you have control over) something like the below: