|
Posted by Jerry Stuckle on 09/02/07 13:13
R. Rajesh Jeba Anbiah wrote:
> On Aug 24, 5:41 am, "burgermeiste...@gmail.com"
> <burgermeiste...@gmail.com> wrote:
> <snip>
>> #1.
>> public function addArrayA($object){
>> //logic
>> $a[] = $object;
>>
>> }
>>
>> public function addArrayB($object){
>> //same logic
>> $b[] = $object;
>>
>> }
>
> This may be a good solution for just 2 object arrays. But, for some
> generalization, I'd prefer:
> public function addArray($object, $key='a'){
> $arr[$key][] = $object;
> }
>
> --
> <?php echo 'Just another PHP saint'; ?>
> Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
>
But this creates much more problems - like keeping track of keys, etc.
Better would be having one array in the object with an "Add" function.
If you need two different arrays, create two different objects.
And if you need to relate the objects, have a second class which allows
you to add as many of these objects as you wish.
This allows as many arrays as the user needs without having to worry
about ensuring you have the correct keys, etc.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|