Welcome Guest, Not a member yet? Register   Sign In
Multi-Dimensional Array Help
#7

[eluser]jwindhorst[/eluser]
@jcargilo it's not necessary to recreate the original array, but for the sake of the next developer that might have to look at the code in the future, I think it's more readable my way. If you had a two categories, let's say fruits and nuts you might have something like this:
Code:
array(
    'fruits'  =>  'items' => array('apple', 'orange', 'pear'),
    'nuts'    =>  'items' => array('pistachio', 'peanuts', 'macedamia')
)

With the pass by reference way, you are going to end up creating two new and distinct arrays. Leaving you with something like I believe:
Code:
$fruits = array( 'items' => array('apple', 'orange', 'pear'));
$nuts   = array( 'items' => array('pistachio', 'peanuts', 'macedamia'));

At that point it really is personal preference. I don't think there is even an optimization question between the two methods although I could be wrong. The reason I say that my way is more readable is simply when you do it by reference you don't see the names of the two arrays you will be left with because they are being generated in a loop.


Messages In This Thread
Multi-Dimensional Array Help - by El Forum - 03-21-2012, 04:57 PM
Multi-Dimensional Array Help - by El Forum - 03-21-2012, 08:05 PM
Multi-Dimensional Array Help - by El Forum - 03-21-2012, 08:07 PM
Multi-Dimensional Array Help - by El Forum - 03-21-2012, 08:44 PM
Multi-Dimensional Array Help - by El Forum - 03-21-2012, 08:51 PM
Multi-Dimensional Array Help - by El Forum - 03-21-2012, 10:58 PM
Multi-Dimensional Array Help - by El Forum - 03-22-2012, 09:23 AM
Multi-Dimensional Array Help - by El Forum - 03-22-2012, 01:43 PM
Multi-Dimensional Array Help - by El Forum - 03-22-2012, 02:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB