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 8868169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:12:22+00:00 2026-06-14T17:12:22+00:00

Does using more variables have any impact on the efficiency of the code? I.E.

  • 0

Does using more variables have any impact on the efficiency of the code?
I.E. does this code:

function get_random_string($valid_chars, $length)
{
    $random_string = "";
    $num_valid_chars = strlen($valid_chars);
    for ($i = 0; $i < $length; $i++)
    {
        $random_pick = mt_rand(1, $num_valid_chars);
        $random_char = $valid_chars[$random_pick-1];
        $random_string .= $random_char;
    }
    return $random_string;
}

work more efficiently than this:

function get_random_string($valid_chars, $length)
{
    $random_string = "";
    for ($i = 0; $i < $length; $i++)
    $num_valid_chars=strlen($valid_chars);
    {
        $random_string .= $valid_chars[mt_rand(1, $num_valid_chars)-1];
    }
    return $random_string;
}
  • 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-14T17:12:23+00:00Added an answer on June 14, 2026 at 5:12 pm

    In the end, you won’t notice the difference unless your real code completly different from the example.

    Remember that even if PHP is not being compiled per se, the code still gets parsed and op-code compiled and even cached. The result can be dramaticaly different from what you coded in the first place.

    Your job as a developper is to make clean, readable code that answer’s the client request. Obviously, don’t use techniques that forcefuly makes the code bloaty and slow, the rest is the Zend Optimizer’s job, don’t worry about it.

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

Sidebar

Related Questions

I have a JavaScript object that does something like this - using a closure
Does Facelets have any features for neater or more readable internationalised user interface text
Does anyone have any opinions on not using prototypes unless necessary for functions declared
Does anyone have any idea if it is possible to put additional variables into
2 questions: Does using MVC make it any easier to build 508/WAI compliant sites?
I am using a proprietary language called VGL which really does not type variables
First off, does anyone have a comprehensive list of the Perl special variables? Second,
I don't have a specific situation I'm dealing with, so consider this more of
I have heard of people using them for keeping track of session variables, but
This is a curiosity more than anything: Does there exist a programming language that

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.