View Single Post
Old 10-02-2009, 10:59 PM   #2 (permalink)
Village Idiot
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by Swiftaxe View Post
Hi,

I need advice about searching through multidimensional arrays.

My array contains product data for a webshop. This is the structure:

PHP Code:
$array = array( $category =>
    array( 
$product =>
       
$id,
       
$title,
       
$price,
       
etc... )); 
There is several categories and in each category many products with it's data. What is a good way to search such an array for a product with a certain ID? I need the keys for each dimension returned so I can extract data from that product.

Is there a way to do this without having nested foreach loops?
Tell me If I am not clear enough.

Any help is greatly appreciated!

/Swiftaxe
Nested foreaches would be the best way, but doing this outside of a database to start with is bad. Why aren't you using a database? SQL queries could search though results literally thousands of time faster.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
Swiftaxe (10-04-2009)