Yes, like nothing complicated?
$json = '{"terminals":[{"token":"hile_abcd1234","name":"Hile Group Authorized Agent","scopes":["r"]},{"token":"hile_absd1234","name":"Hile Group Authorized Agent 2","scopes":["w"]}]}'; $data = json_decode($json, true); $result = null; $needle = "hile_absd1234"; foreach($data['terminals'] as $t){ if($t['token'] === $needle){ $result = $t; break; } } print_r($result);
as already described by @ splash58, you can use array_filter , but here you will end up with an array, inside which is the desired result. An alternative could be array_reduce
$result = array_reduce($data['terminals'], function($carry, $item) use ($needle){ if($item['token'] === $needle){ $carry = $item; } return $carry; }); print_r($result);
it will immediately return the desired array.
the disadvantage of both functions of arrays is that they will scan the entire array completely, while in the loop we can make a break after finding the element.