You are here: Re: Recurse an array with an object/s « PHP Programming Language « IT news, forums, messages
Re: Recurse an array with an object/s

Posted by Aggelos on 02/08/07 11:51

> Actually, allow me to correct one thing. This is an N-dimensional array
> (depending on the depth). But you are handling it as a single
> dimensional array in your recursive function. This is perfectly fine,
> and I do similar things quite regularly.

I happy to hear that. It is good to listen that I haven't used a
technique that is so awkward to be used from otheres.

At the moment what I did with my ricursive function works perfect.
The question is if that's the right way to do it...

And that is an object haveing as an attribute another object and that
object laso have another object as an attribute:
oject -> object -> object

or is it better to keep them sepperate and just use their unique id's
to link the two objects (thats what I am doing until now)

So again:

1st way *******************************
*****************************************
class package {
var $packageId;
var $productArray = array();

function package($packageId=NULL) {
$this->packageId = $packageId;
$this->productArray = product::select(....);
}
}
class product {
var $productId;
var $attributesArray = array();
function product($productId=NULL) {
$this->productId = $productId;
$this->attributesArray = attribute::select(....);
}
}
2nd way *******************************
*****************************************
class package {
var $packageId;
function package($packageId=NULL) {
$this->packageId = $packageId;
}
}
class product {
var $productId;
function product($productId=NULL) {
$this->productId = $productId;
}
}

$product_packages = select the products from product_package table
//$product_packages = array('pacakge_id','product_id') <- just to have
an idea of how that array looks like
foreach($product_packages as $packageId => $productArray) {
foreach($productArray as $productId => $productValue) {
$product[$productId] = new product($productId);
}
}

Anyway... that's not like the full code but you could get an Idea of
how I am working...
I hope it makes sense.
Can you just tell me which way could be better ? more efficient
probably ...

At the moment for every Many to Many relationship I am using a
seperate class e.g. product_package

Thanks
Angelos

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация