Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9168675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:40:54+00:00 2026-06-17T15:40:54+00:00

I doubt that it makes a huge impact on performance, but I was wondering

  • 0

I doubt that it makes a “huge” impact on performance, but I was wondering if PHP Loops are better optimized than spitting out HTML with PHP variables instead?

A very simple example would be something like this:

which is “more efficient”:

<?php
$i = 0;
$settings = array(
    1   => 'var_a|var_one',
    2   => 'var_b|var_two',
    3   => 'var_c|var_two',
    4   => 'var_d|var_three',
);
foreach($settings as $setting) {
    $e = explode('|', $setting);
    if(get_option($e[0]) !== ''){ ?>
        <li class="radio">
            <h2><?php print($e[1]); ?></h2>
            <input name="radio_ask" type="radio" value="<?php print($e[0]); ?>" id="radio_<?php print($i); ?>" tabindex="<?php print($i); ?>" onclick="this.setAttribute('checked', 'checked'); this.checked = true;">
        </li>
    <?php }
} 
?>

or

<?php 
if(get_option('var_a') !== ''){ ?>
    <li class="radio">
        <h2><?php print( get_option('var_one')); ?></h2>
        <input name="radio_ask" type="radio" value="<?php print( get_option('var_a')); ?>" id="radio_1" tabindex="1" onclick="this.setAttribute('checked', 'checked'); this.checked = true;">
    </li>
}
if(get_option('var_b') !== ''){ ?>
    <li class="radio">
        <h2><?php print( get_option('var_two')); ?></h2>
        <input name="radio_ask" type="radio" value="<?php print( get_option('var_b')); ?>" id="radio_2" tabindex="2" onclick="this.setAttribute('checked', 'checked'); this.checked = true;">
    </li>
<?php } ?>
<?php 
    //etc. etc.
?>

The basis for this question, is I have some code I wrote a long time ago, and I’ve learned a LOT since then. I want to clean it up a little bit. (things like print($this); print($that); instead of print($this.$that); and the like, include the above.

I just want to make sure that moving to the “uppermost” example is either better, or just a better/cleaner practice way of doing things. I’d hate to move forward with something I think looks cleaner, but is bad for some reason I don’t see

Edit: Sorry for any hiccups with the code, I wrote it on the spot as a simple example

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:40:56+00:00Added an answer on June 17, 2026 at 3:40 pm

    Short answer

    DRY (Don’t repeat yourself) is a principle you should be more afraid of instead of “Perfomance”.
    Therefore you should go with loops.

    Long answer

    Consider for an (horrible) moment to have the second code; a long list of the same code repeat over and over again for like 20 times. Let’s just imagine you want to add 10 more: with the first you just change the loop at the beginning (1 line), with the second you create something like 100 more lines of code. Then assume you want to change a bit of each code: with the second you have to edit that piece of code for 30 times, with the first… well I think you got the concept.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic doubt that, How can we have both CLR's on a
I have a doubt that when I am converting a String to date then
Yes, as you might guess, I want to ask about Cloud-computing. I doubt that
This is a small doubt and something that shouldn't really come to one's mind.So
I have a very basic doubt regarding the method that gets executed when app
I have a little doubt about javascript, a new language that I'm studying... I
I had this doubt for sometime now, some people say that there's no such
Please help me to clear my doubt. I develop an application that performs uninstall
aka, Seeking generic Error Handler (ΟΚ to use commercially) I doubt that I am
I have the following problem/doubt that I hope somebody could help me with. Let's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.