10-02-2009, 10:59 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by Swiftaxe
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.
|
|
|
|