PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 19th, 1999, 01:41 PM
hicc01
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Does anyone know how to combine two variables into one? I have two variables containing information.

$a and $i
$a = a1 is a variable sent from a previous page, and I want to output the variable within a loop because there are more variables (a1, a2, a3, a4 .....)

so what I'm trying to do is this:

$i = 1
while ( $i <= 4 ) {

here I want to echo a1 by $a&$i Does anyone know how to put these two together? so I can output in the loop?

$i++;
}

thanks, I hope you guys can understand what I'm asking for....

Reply With Quote
  #2  
Old September 19th, 1999, 04:57 PM
ExPulse
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
$hello = 'Hello ';
$world = 'World';

$hw = "$hello"."$world";

echo $hw;

This combines the two strings to form one and would print 'Hello World'

Reply With Quote
  #3  
Old September 21st, 1999, 05:24 PM
horaR
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
If I understand well you have:
$a1 = "Var 1";
$a2 = "Var 2";
$a3 = "Var 3";
and you want to access them in a loop.
Try
$i = 1;
while ($i < 4) {
eval("$a = "$a$i";");
print("a$i = $an");
$i++;
}

Be carefull with the escaped (with the slash) symbols.
I hope this works.

Reply With Quote
  #4  
Old September 23rd, 1999, 11:23 AM
moderator
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Alternatively you could do it like this:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
$a1 = "Var 1";
$a2 = "Var 2";
$a3 = "Var 3";

$i = 1;
while ($i < 4) {
$temp="a".$i;
print "a$i = $$tempn";
$i++;
}
[/quote]
Just a matter of personal prefrence, I guess.

Reply With Quote
  #5  
Old September 23rd, 1999, 12:32 PM
horaR
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Maybe it's my fault but the above code (by moderator) does not work for me.
I am using PHP 3.0.12, and the ouput of the script was:
a1 = $a1
a2 = $a2
...
where it should be:
a1 = Var1
a2 = Var2
...
The aditional '$' did not work for me and left me a doubt:
Is that an option in PHP.INI or a compile time option?
thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Should be pretty simple.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap