Array reference by id rather than key

There are a number of different situations in which I would like to be able to access an array (say, $products or $categories) using the id for that data type (e.g., product id or category id, respectively) as the array reference, rather than the oridinal that appears to be set as the key.



With that capability I could, for example, easily list in a given product detail page the categories to which that product is assigned. The $product variable provides me a list of all the additional subcategories assigned to the product, and I could use the category_id of each as a reference into the $categories array. As it stands now, unless I’m missing something, I have to crawl the $categories array looking for the array element whose category_id matches the one I’m looking for.



Any insight would be appreciated!