Is there a way to get a JSON object out of a JSON object array depending on its value?
What I've got:
$users = [{"id":1, "name":"Some Name"},
{"id":2, "name":"Another Name"},
{"id":3, "name":"Third Name"}];
And what I want is to pull out the user depending on the id. So I might have an AJAX call that sends in user=2
. What I want is to pull the user with an id of 2 from the JSON array.
I'm wondering if this is the best way to do it or not. I have full access to set up the JSON array another way, if that would make it easier.