How to organize arrays

3

In the Pear documentation, it defines a pattern for how to assemble the structure of an array :

$some_array = array(
    'foo'  => 'bar',
    'spam' => 'ham',
);

In this way, I already use, it separates legibly the elements, but what about an array with say 100 elements. The code will be too long, is it still correct?

Is this the only standard to follow? Are there any other indications of how this structure should be organized?

    
asked by anonymous 25.09.2015 / 22:35

1 answer

2

No, it's the same thing. You can not do more organized than this, unless there is some specific situation that helps. You can skip a line to separate blocks that make sense. Or you can reassess if you need all elements together in the array . It depends on the situation.

At last, it's like. This is a good standard, but the important thing is to be readable. Worse would be to squeeze everything because you have too much information.

If it makes sense because in the code, put in the code. Just leave out the code if there is a reason for this. If the information should come from external source because the requirement asks for it, either to facilitate maintenance, configuration, etc. it does not matter because the data will be loaded into the array without having to worry about the syntax getting large and confusing.

    
25.09.2015 / 23:07