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

  • SEARCH
  • Home
  • 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 7919439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:51:56+00:00 2026-06-03T15:51:56+00:00

In any programming language (like php, java, javascript etc) is it possible to dynamically

  • 0

In any programming language (like php, java, javascript etc) is it possible to dynamically create a changing number of variables in a loop, within a given name space?

for example, if I want to create N variables that have random numbers between 1 and 5, which are to be called random1, random2 .. randomN, is it possible to do something like:

loop ( N ){<br>
  create variable randomN = random(1,5);<br>
}
  • 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-03T15:51:59+00:00Added an answer on June 3, 2026 at 3:51 pm

    In PHP you could use variable variables:

    $N = 5;
    for ($i = 0; $i != $N; ++$i) {
        ${"random$i"} = rand(1, 5);
    }
    

    In JavaScript, same thing:

    var N = 5;
    for (var i = 0; i != N; ++i) {
        window['random' + i] = Math.round(Math.random() * 5);
    }
    

    Though, I would recommend using a “container” to hold those variables, so that they’re not created globally.

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

Sidebar

Related Questions

Aside from language-specific constructs, for someone who is programming in PHP, javascript, java, and
Are there any open source or commercial web programming language that function much like
In nearly any programming language, if I do $number = rand(1,100) then I have
Is there any programming language (or type system) in which you could express the
Does any one know in which programming language were Google Talk application developed. yes
Is there any really low level programming language that can get access the memory
Update: This question is a duplicate of Are there any programming languages targeting PHP,
Why in java (I dont know any other programming languages) can an identifier not
I was thinking whether it is possible to bridge asp.net, php and java to
PHP is my first programming language. I can't quite wrap my head around when

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.