Jump to content

Too many Variables vs Arrays


silvercover

Recommended Posts

Hi,

 

Which one is better from performance view (CPU usage and etc)? using too many Variables or a single Associative Array or generally an Array?

 

This one:

$ld_linkdump_title         = get_option('ld_linkdump_title');
$ld_linkdump_widget_title  = get_option('ld_linkdump_widget_title');
$nw_option                 = get_option('ld_open_nw');
$ld_open_branding          = get_option('ld_open_branding');
$ld_stylesheet_option      = get_option('ld_stylesheet');
$ld_number_of_links        = get_option('ld_number_of_links');
$ld_number_of_links_widget = get_option('ld_number_of_links_widget');
$ld_number_of_rss_links    = get_option('ld_number_of_rss_links');
$ld_number_of_links_be     = get_option('ld_number_of_links_be');
$ld_repeated_link          = get_option('ld_repeated_link');
$ld_linkdump_fd            = get_option('ld_linkdump_fd');
$ld_linkdump_rss_desc      = get_option('ld_linkdump_rss_desc');
$ld_branding_bg            = get_option('ld_branding_bg');
$ld_archive_days           = get_option('ld_archive_days');
$ld_archive_pid            = get_option('ld_archive_pid');
$ld_show_counter           = get_option('ld_show_counter');
$ld_show_description       = get_option('ld_show_description');
$ld_show_description_w     = get_option('ld_show_description_w');
$ld_send_notification      = get_option('ld_send_notification');
$ld_auto_approve           = get_option('ld_auto_approve');
$ld_short_url              = get_option('ld_short_url');

 

or this:

 

$options['ld_linkdump_title'] = get_option('ld_linkdump_title');
$options['ld_linkdump_widget_title']  = get_option('ld_linkdump_widget_title');
$options['nw_option']                 = get_option('ld_open_nw');
.
.
.

Link to comment
Share on other sites

I cannot give you an answer which I can say, this is the correct way to do but...

 

I think it is much easier for the developer to handle an array than so much variables!

I think is more faster with CPU because if not why should it be used so much in specially frameworks.

Say codeigniter, they want arrays all the time.

 

And I don't think it is a different you even can see...

 

Now you got a answer from me better than nothing =)

Link to comment
Share on other sites

I prefer an array.  I don't think there is any CPU difference at all and you can group things as you have shown in a $config array and an $options array, etc.  Also consider how you would pass these around to functions etc.  Much easier to pass $options than it is to pass around 50 variables.  Also, if you define individual variables in the global scope they will be in the $GLOBALS array anyway.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.