473,660 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to combine the results of two variables to echo another variable?

Hello,
I'm a somewhat PHP newbie, so please bear with me.

Here is what I am trying to do:

$foobar = "blah blah";
$a = "foo";
$b = "bar";
$fooboo = "$a" . "$b";
echo $fooboo

I know my syntax here is not correct so I am looking for the function
to make $fooboo echo out the $foobar variable "blah blah", and not as
"foobar".

Any help is appreciated.

Jul 17 '05 #1
12 51160
Dave wrote:
Hello,
I'm a somewhat PHP newbie, so please bear with me.

Here is what I am trying to do:

$foobar = "blah blah";
$a = "foo";
$b = "bar";
$fooboo = "$a" . "$b";
echo $fooboo

I know my syntax here is not correct so I am looking for the function
to make $fooboo echo out the $foobar variable "blah blah", and not as
"foobar".

Any help is appreciated.


Variable variables:
http://nz.php.net/manual/en/language...s.variable.php

$foobar = "blah blah";
$a = "foo";
$b = "bar";
$fooboo = "$a" . "$b";

$fooboo = $$fooboo;

echo $fooboo

Sacs
Jul 17 '05 #2
Sacs wrote:
Variable variables:
http://www.php.net/manual/en/languag...s.variable.php
Yes. But why......:
$fooboo = "$a" . "$b";


Just do: $fooboo = $a . $b;
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #3
Ewoud Dronkert wrote:
Sacs wrote:
Variable variables:
http://www.php.net/manual/en/languag...s.variable.php

Yes. But why......:


Variable variables are one of the most powerfull features of php I've
found. Very usefull when you dont know how many variables to be
processed in a form for e.g.

for( $i=1; $i <= $num_fields; $i++) {
$blah = "field_" . $i;
// $blah is now "field_1" first time through the loop

$blah = $$blah;
// now $blah holds what was input into the appropriate input
}

echo '<form>
<input type=text name="field_1">
<input type=text name="field_2">
<input type=text name="field_3">
<input type=hidden name="num_field s" value=3>
<input type=submit>
</form>';

$fooboo = "$a" . "$b";

Just do: $fooboo = $a . $b;

With just $fooboo = $a . $b; then $fooboo is set to "foobar" not "blah
blah" as op wanted.

Sacs
Jul 17 '05 #4
Sacs wrote:
$fooboo = "$a" . "$b";


Just do: $fooboo = $a . $b;

With just $fooboo = $a . $b; then $fooboo is set to "foobar" not "blah
blah" as op wanted.


Sigh. I meant: why use the quotes, they're not needed! (and yes, then use
$$fooboo, just like in the code a few posts up).
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #5
Or simply use arrays instead (preferred by most):

<form method="POST">
<input type=text name="field[]">
<input type=text name="field[]">
<input type=text name="field[foo]">
<input type=submit>
</form>

foreach ($_POST['field'] as $key => $value) {
...
}

http://php.net/manual/en/faq.html.php#faq.html.arrays

Jul 17 '05 #6
Ewoud Dronkert wrote:
Sigh. I meant: why use the quotes, they're not needed! (and yes, then use $$fooboo, just like in the code a few posts up).


It seems the PHP community likes to put quotes around variables.
It's baffeling.

Jul 17 '05 #7
Philip Olson wrote:
Or simply use arrays instead (preferred by most):

<form method="POST">
<input type=text name="field[]">
<input type=text name="field[]">
<input type=text name="field[foo]">
<input type=submit>
</form>

foreach ($_POST['field'] as $key => $value) {
...
}

http://php.net/manual/en/faq.html.php#faq.html.arrays

Where's the fun in that! My way was much harder to comprehend, must be
perl haunting me....

Actually, never thought of passing back an array in a form... hmmm....

:-)
Sacs
Jul 17 '05 #8
Ewoud Dronkert wrote:
Sigh. I meant: why use the quotes, they're not needed! (and yes, then use
$$fooboo, just like in the code a few posts up).

Oh. Wrong end of stick. :-)

And I don't know why so many people put quotes around variables in PHP.
*shrug*

Sacs
Jul 17 '05 #9
There is no need for variable variables at all. Use arrays for stuff
like this. Yeah, v-vars are indeed powerfull, powerfull to lead ppl to
unpredictable clutter up the root of the namespace and write ugly code
-- like demonstrated below in all beauty.

On 29.04.2005 00:51, Sacs wrote:
Ewoud Dronkert wrote:

Variable variables are one of the most powerfull features of php I've
found. Very usefull when you dont know how many variables to be
processed in a form for e.g.

for( $i=1; $i <= $num_fields; $i++) {
$blah = "field_" . $i;
// $blah is now "field_1" first time through the loop

$blah = $$blah;
// now $blah holds what was input into the appropriate input
}

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2025
by: David | last post by:
Can anyone give me some help or tips in converting this code to take 2 variables that will specify the number of Pack type lines and the number of Single type lines. We use it to create a web page that allows us to split a garment delivery over multiple dates and and to specify the number and size of garments in a pack and the number and size of individual garments in the delivery. 3 of each has been enough until now. However we are finding...
3
2701
by: Marc | last post by:
Hi all, I can't remember how to do this. I have several instances of telnet connections that I label conn2,conn3, etc. Later when I want to scroll through all of these I wanted to do something like this: for int in range(2, 9): use... conn+str(int) {I'm passing it into another
4
1885
by: s99999999s2003 | last post by:
hi the database "execute" function returns a list of logical results. Each logical result is a list of row tuples, as explained in the documents. everytime i use it to execute various statements, it returns me, for example (, , ) and sometimes , (, ) or () in my call, i give eg (a,b,c) = db.execute(stmt) so that it returns me (, ,
2
1123
by: Jerry Spence1 | last post by:
Sorry for the confusing title - not quite sure what I'm after here. I think need to have a static variable in a procedure, but the name of that variable will be designated at run time. Also I don't know how many variables I need until run time either! Just to explain, I have a number of IP based door access control readers and I need to retain a status flag about certain ones - I don't know which ones until run time. The readers have...
3
3114
by: Imran Aziz | last post by:
Hello All, I have a dataset that I populate using a SQL Server database, and the second one that I populate using a mySQL Server database, I need to combine the results in memory and then sort them, how do I go about doing that ? This is a search query, so I do not want to create another temp table to do this, any idea's please. Imran.
1
1469
by: iLL | last post by:
Is there any way to save the result of a "test" command in a variable, or would I have to do something like: bool=`if ; then echo 1; else echo 0; fi;`
10
5841
sumaiya
by: sumaiya | last post by:
The problem is explained below: 1- on a php page i have $x=2; 2- there is a mysql table with a field called "layout" 3- The data in "layout" field = My problem number is $x 4- Now what i want is when i do echo $layout it shoud display My problem number is 2
3
4401
by: Vik Rubenfeld | last post by:
I have to search 2 mySQL tables, and show the user a single sorted list that contains all the results from both mySQL queries. My question is, how do you get all the resulting items from both databases into one single, sorted list, to present to the user? I guess one way would be, to use PHP to copy all the results from each database, into a PHP array, and then sort it. Is that how this kind of thing is usually done?
8
3974
by: vineetbindal | last post by:
Hi All. I have two Columns column1 and column2. i have to run a query with some value from colum1 depending on it will select result from coloumn2 and if that result is present in coloumn 1 it will again select something from coloum2 again if that new result is present in coloum 1 it will select something from colum2 . i have to combine all this in one column without repeating values. something like. Column1 Column2 Column3 2100 ...
3
1333
by: perhapscwk | last post by:
I have $ad_url = "https://".$_SERVER."/category.php?viewadv=".$viewadv; echo $ad_url; It always show as
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.