I am writing an app that allows users to modify and change some of their site settings. I am just constructing a form generator that will send various options to variuous plugins to generate the code what I am wondering is whether I should be using objects for this rather than multidimensional arrays? If so how would I change my code?
So right now I have made this- its very long and going to get longer so I have only pasted part of it for the sake of brevity:-
$scopeSettings = array(
'site_background' => array(
'subpanels' => array(
'colour' => array(
'plugins' => array(
'colourchooser' => array(
'tip' => "The background colour appears underneath the 'Background Image' (if set)-hover over the '?' around the colour chooser for extra tips on how to use it",
'element' => 'body',
'gradientenabled' => 'true',
'opts' => array (
'closed' => 'true',
'advanced' => array(
'tip' => "You can paste in your own generated gradient codes in here",
'checkbox' => true
)//end advanced
)//end Opts
)//end colour chooser
)//end plugins
),//end colour sub panel
'pattern' => array(
'plugins' => array(
'patternselector' => array(
'tip' => "Use the pattern selector to apply effects like moire or scan lines to your background image",
'element' => 'patimg'
)//end patternselector
)//end plugins
),//end pattern sub panel
)//end subpanels
)//end site background
);//end scope settings
What would be best practice with this sort of thing?
Think about what your particular data represents: If it's a single entity with named properties, you want an object. If it's a group of entities of the same type/shape, or if order matters, you likely want an array.
The difference between an array numeric and an associative array is a mere 5%, so you can say that they are the same. The use of an object is +100% slower but it is still acceptable in most conditions (aka it uses the double of time).
Objects represent a special data type that is mutable and can be used to store a collection of data (rather than just a single value). Arrays are a special type of variable that is also mutable and can also be used to store a list of values.
Answer: Use the Array. isArray() Method You can use the JavaScript Array. isArray() method to check whether an object (or a variable) is an array or not. This method returns true if the value is an array; otherwise returns false .
Maybe this is a stupidity, but you can use "YAML" or "JSON" as configuration format for an application no?
As for example Symfony or other framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With