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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:28:31+00:00 2026-06-11T19:28:31+00:00

What I am doing that I want to generate a list based on how

  • 0

What I am doing that I want to generate a list based on how many items are in an array, so I have counted the items and loop over them, create a number based var and construct a string $var which contains $a1,$a2…. and assigns the $var to list list($var)

and tried to access $a1 but it gives me the error “Undefined variable: a1”

Is there any other way to do it?

Here is my code:

$arr = array('1','2','3');
$listsize = count($arr);
$var='';
for($i=1;$i<=$listsize;$i++){
        $var.='$a'.$i;
        if($i!=$listsize){
            $var.=',';
        }
}

list($var) = $arr;
echo $a1;
  • 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-11T19:28:32+00:00Added an answer on June 11, 2026 at 7:28 pm

    What you are looking for is variable variables.

    In PHP, you can dynamically assign variables names (not just values).

    Here is an example:

    $foo = "Hello" . 1;
    
    # In this line, I am taking the value of the variable $foo (Hello1) and
    # using that as as a variable name. This is equivalent to
    # $Hello1 = "World", except the variable is dynamic (hence variable variables).
    
    $$foo = "World";
    
    print $Hello1; # This will print World
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface that I want to implement in separate classes after doing
I want to create a tag list for a Lucene document based on a
I'm drawing circle and want that when lines match together then generate error.I have
I have a list of products I want to generate xml for currently all
I want that the form will not close by doing Alt + F4 but
I am doing game for iphone.In that I want to store game data such
I'm doing a kinect Application using Kinect SDK . The Result I want that
I execute some tests within my application, but before doing that I have to
I need to random some elements from an array. I'm doing that by randomizing
i have two collections of the same objects (same size list of course). items

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.