•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,565 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,604 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 443 | Replies: 8 | Solved
![]() |
I have a variable in a variable.
I have done this before but it is not working this time.
I have it in a for loop so my code is:
The out come should be "one two", correct?
The concept is correct? The code is correct? - to the best of my knowledge and references.
Any ideas? Thanks, Regards X.
I have done this before but it is not working this time.
I have it in a for loop so my code is:
php Syntax (Toggle Plain Text)
$abc1 = one; $abc2 = two; for($i = 0; $i < 2; $i++) { echo $$abc$i; }
The out come should be "one two", correct?
The concept is correct? The code is correct? - to the best of my knowledge and references.
Any ideas? Thanks, Regards X.
•
•
Join Date: May 2008
Location: Swindon, UK
Posts: 117
Reputation:
Rep Power: 1
Solved Threads: 20
The best way to do this would probably be an array:
$abc=array("value1","value2");
for($i = 0; $i < 2; $i++) {
echo $abc[$i];
}•
•
Join Date: May 2008
Location: Swindon, UK
Posts: 117
Reputation:
Rep Power: 1
Solved Threads: 20
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
•
•
I have a variable in a variable.
I have done this before but it is not working this time.
I have it in a for loop so my code is:
php Syntax (Toggle Plain Text)
$abc1 = one; $abc2 = two; for($i = 0; $i < 2; $i++) { echo $$abc$i; }
The out come should be "one two", correct?
The concept is correct? The code is correct? - to the best of my knowledge and references.
Any ideas? Thanks, Regards X.
The output will not be one two because $abc1 is one and not $abc0. Try this.
php Syntax (Toggle Plain Text)
<?php $abc1 = "one"; $abc2 = "two"; for($i = 1; $i <= 2; $i++) { echo ${abc.$i}; //value of $i will be concatenated to string abc and then it will consider the whole as a variable } ?>
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Heh! I tested it before posting it here and I am 200% sure it will work..
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- multiple variables in a mod_rewrite URL string (Linux Servers and Apache)
- Problem with variables in Windows shell script (Windows NT / 2000 / XP / 2003)
- how can i used session and cookies ??? (PHP)
- Problem Unsetting Variables? (PHP)
- C++ Syntax (C++)
- Classes (C++)
- Data Abstraction (Computer Science and Software Design)
- Locality (C)
Other Threads in the PHP Forum
- Previous Thread: php / sql insert script error
- Next Thread: Image in xml



Linear Mode