silvercover Posted January 24, 2011 Share Posted January 24, 2011 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'); . . . Quote Link to comment https://forums.phpfreaks.com/topic/225534-too-many-variables-vs-arrays/ Share on other sites More sharing options...
webbhelp Posted January 24, 2011 Share Posted January 24, 2011 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 =) Quote Link to comment https://forums.phpfreaks.com/topic/225534-too-many-variables-vs-arrays/#findComment-1164565 Share on other sites More sharing options...
AbraCadaver Posted January 24, 2011 Share Posted January 24, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225534-too-many-variables-vs-arrays/#findComment-1164605 Share on other sites More sharing options...
Anti-Moronic Posted January 24, 2011 Share Posted January 24, 2011 Without a doubt, use arrays. Performance is a non-issue in this regard. Worry about the performance of the developer working on the code! If you use individual variables like you have above, be prepared to manage one hell of a nightmare come refactoring time. Quote Link to comment https://forums.phpfreaks.com/topic/225534-too-many-variables-vs-arrays/#findComment-1164687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.