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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:16:48+00:00 2026-05-31T22:16:48+00:00

I can make a variable’s name from two variables’ value: $a = ‘tea’; $b

  • 0

I can make a variable’s name from two variables’ value:

$a = 'tea';
$b = 'pot';
$tea_pot = 'Too Hot';

Here if I print or echo ${$a.'_'.$b}, I will get ‘Too Hot’ as output.

Similarly I need to make an array’s name from two variables’ value.
I try this the code below. But it’s giving me an error: Undefined variable.

I want something like:
$k = ${'B'.$a} where $a=5 and $B5 = array('c', 'v', 'b');
and want to echo($k[2]);

the codes that i want to solve is here…

$B0 = array('apple', 'crow', 'monkey', 'lion', 'deer', 'bear', 'tiger');
$B1 = array('bad', 'meaningless', 'odd', 'no fare', 'poor', 'old', 'dirty', 'damn', 'rush');
function($set, $number){
     while($set >= 2){
          $set -= 2;
     }
     if($set == 0){
          while($number >= 7){
               $numbur -= 7;
          }
     } else {
          while($number >= 9){
               $numbur -= 9;
          }
     }
     $array = ${'B'.$set}; // Error
     return $array[$number];
}
/*Error: it is saying that here the "${'B'.$set}" is a Undefined variable
where it is a name of an array. what can I do to realize
that it is not a variable but an array.*/
  • 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-05-31T22:16:49+00:00Added an answer on May 31, 2026 at 10:16 pm

    I got the real problem and its solve…
    Here the arrays “B0” and “B1” are places outside the function so you have to declare the ${‘B’.$set} as a global array by just adding a single line inside the function before you call it. Like this:

    $B0 = array('apple', 'crow', 'monkey', 'lion', 'deer', 'bear', 'tiger');
    $B1 = array('bad', 'meaningless', 'odd', 'no fare', 'poor', 'old', 'dirty', 'damn', 'rush');
    function($set, $number){
         while($set >= 2){
              $set -= 2;
         }
         if($set == 0){
              while($number >= 7){
                   $numbur -= 7;
              }
         } else {
              while($number >= 9){
                   $numbur -= 9;
              }
         }
         global ${'B'.$set};
         $array = ${'B'.$set};
         return $array[$number];
    }
    

    now it will understand and will get the array properly and will not show any errors.

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

Sidebar

Related Questions

In PHP, you can make two variables point to the same data. $a =
How can I make a variable into a key or a value so that
How can I make a variable (object) available for the whole lifetime of the
I know I can make a new variable by simply saying $var = stuff
I can make the compiler give me an error (Use of variable prior to
While reading from a site a read that you can not make a global
I was wondering if I can make my code clearer by indicating one variable
How can you make a javascript variable and use it with jQuery? I use
My question is, how I can make a cluster analysis from spatial - temporal
How can I make a variable accessible across slides in PowerPoint 2007? I tried:

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.