Arrays of arrays in PHP


Ratkey

I love how quick and easy it is in PHP to declare complex data structures of associative arrays within arrays within arrays.

Consider the array below that starts with string prompt:

 
 32   var $arrFilters = array(
 33     '0' => array(                
 34       'strPrompt' => 'Preset Reports...',
 35     ),
 36     '1' => array(
 37       'strPrompt' => 'Email Opens',
 38       'FILTER_1' => array(
 39         'strValue'  => 'email',
 40         'strFind'   => 'exact',
 41         'strColumn' => FILTER_COLUMN_HOW,
 42       ),
 43     ),
 44   );

The string prompt is then used to build the HTML selector. A neat outcome of this is when the structure is displayed while debugging using

echo “<pre>” . print_r($this->arrFilters, true) . “</pre>”;

Array
(
    [strPrompt] => Email Opens
    [FILTER_1] => Array
        (
            [strValue] => email
            [strFind] => exact
            [strColumn] => how
        )

)

The prompt clearly displays what the data is. Sweet.

 42       ),
 43     ),
 44   );

I also love that…

View original post 19 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s