473,651 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ampersand before var in function

Hi there,

Recently i noticed a few times an ampersand in front of a variable in a
function.
Like so:

function foo( &$bar )
{
// do something
};

What is it for? I can't figure it out ...

Frizzle.

Mar 17 '06 #1
4 2742
frizzle wrote:
Hi there,

Recently i noticed a few times an ampersand in front of a variable in a
function.
Like so:

function foo( &$bar )
{
// do something
};

What is it for? I can't figure it out ...

Frizzle.

from:
http://www.softwareprojects.org/php-functions-12.htm

Another way to access the data outside the function, without using an
argument is by using a reference to a variable as an argument. You can
do this by placing an ampersand “&” in front of the argument, when you
define the function. This way, the function will directly access the
variable thru the reference, and the variable can be assigned and read
at the same time.

Mar 17 '06 #2

noone wrote:
frizzle wrote:
Hi there,

Recently i noticed a few times an ampersand in front of a variable in a
function.
Like so:

function foo( &$bar )
{
// do something
};

What is it for? I can't figure it out ...

Frizzle.

from:
http://www.softwareprojects.org/php-functions-12.htm

Another way to access the data outside the function, without using an
argument is by using a reference to a variable as an argument. You can
do this by placing an ampersand "&" in front of the argument, when you
define the function. This way, the function will directly access the
variable thru the reference, and the variable can be assigned and read
at the same time.


Hmm, could you maybe give me a small simple example ?

Thanks.

Frizzle.

Mar 17 '06 #3
frizzle in news:11******** *************@z 34g2000cwc.goog legroups.com wrote:
noone wrote:
frizzle wrote:

Hi there,

Recently i noticed a few times an ampersand in front of a variable in a
function.
Like so:

function foo( &$bar )
{
// do something
};

What is it for? I can't figure it out ...


from:
http://www.softwareprojects.org/php-functions-12.htm

Another way to access the data outside the function, without using an
argument is by using a reference to a variable as an argument. You can
do this by placing an ampersand "&" in front of the argument, when you
define the function. This way, the function will directly access the
variable thru the reference, and the variable can be assigned and read
at the same time.


Hmm, could you maybe give me a small simple example ?


function modify_arg1(&$a rg1, $arg2)
{
$arg1 = 'first';
$arg2 = 'second';
}

$arg1 = 1;
$arg2 = 2;
modify_arg1($ar g1, $arg2);
echo $arg1;
echo $arg2;

Outputs:
first
2

Hope this helps!
--
ColdShine

"Experience is a hard teacher: she gives the test first, the lesson
afterwards." - Vernon Sanders law
Mar 18 '06 #4

ColdShine wrote:
frizzle in news:11******** *************@z 34g2000cwc.goog legroups.com wrote:
noone wrote:
frizzle wrote:

Hi there,

Recently i noticed a few times an ampersand in front of a variable in a
function.
Like so:

function foo( &$bar )
{
// do something
};

What is it for? I can't figure it out ...

from:
http://www.softwareprojects.org/php-functions-12.htm

Another way to access the data outside the function, without using an
argument is by using a reference to a variable as an argument. You can
do this by placing an ampersand "&" in front of the argument, when you
define the function. This way, the function will directly access the
variable thru the reference, and the variable can be assigned and read
at the same time.


Hmm, could you maybe give me a small simple example ?


function modify_arg1(&$a rg1, $arg2)
{
$arg1 = 'first';
$arg2 = 'second';
}

$arg1 = 1;
$arg2 = 2;
modify_arg1($ar g1, $arg2);
echo $arg1;
echo $arg2;

Outputs:
first
2

Hope this helps!
--
ColdShine

"Experience is a hard teacher: she gives the test first, the lesson
afterwards." - Vernon Sanders law


Ha that's great! So it changes a variable that exists before the
function is called!
Cool.

Frizzle.

Mar 18 '06 #5

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

Similar topics

5
34696
by: Magnus Warker | last post by:
Hi, when I try to pass some parameters in an URL, I always get an URL where the ampersand is represented as '&'. I tried: $url = "wsp.php?mod=$mod&sec=$sym"; $url = "wsp.php?mod=$mod" . '&' . "sec=$sym";
0
4110
by: debk | last post by:
Server.UrlEncode is not longer converting the ampersand in a string to %26 so the value passed in the querystring gets truncated in the following page. Is this a problem with IIS, does anyone know? I can't find this reported anywhere else. I may just have to code around it. Details: link is created by the following code: <a>href="GroupDetails.asp?groupName=<%=Server.URLEncode(objRecordset("Group_Name"))%>">Group Details</a> If...
0
1398
by: Alexander Grigoriev | last post by:
I hope Mr. Stroustrup can give an answer to this question: What was rationale behind the requirements to use an ampersand and a fully qualified name of a function, to form a pointer to a member function? Is there any syntax ambiguity without those? MS C++ compiler is quite happy when a plain function name is used (I haven't tried it in ANSI compliance mode, though), so for long time I've been pretty sure that it's OK...
2
6702
by: RD | last post by:
Some of the customers in the table I'm trying to see in an XML doc have an ampersand in the data. Looking at them and formatting the XML doc with a style sheet this generates an error. I'm creating the XML doc with VB.Net code, simply writing extracted values from my database to the XML doc. What do I have to do so that the ampersands in the data does not create problems while viewing the XML? Any help would b egreatly appreciated. ...
4
3726
by: tfortney | last post by:
I created an iframe HtmlGenericControl that has an ampersand in the "src" attribute..... Dim faxFrame As New HtmlGenericControl("iframe") faxFrame.Attributes.Add("width", "100%") faxFrame.Attributes.Add("height", "90%") faxFrame.Attributes.Add("frameborder", "no") faxFrame.Attributes.Add("src", "/archive/view.aspx?isPlugin=" & isPlugin & "&iDoc=" & Server.UrlEncode(intDoc))
1
2881
by: Prasanna Padmanabhan | last post by:
I want to process requests to certain image files that have a custom ..icon(32x32) extenstion with a custom .NET HttpHandler in order to be able to tap into Application events. This works fine almost everytime except that I get a 404 error when trying to access a file with an ampersand in its name. The error happens only if I point the aspnet_isapi.dll to the .NET Framework 1.1. If I use the aspnet_isapi.dll of the old .NET framework...
9
2356
by: keepyourstupidspam | last post by:
Hi, I am passing a string to my tokenize function, if the string contains an ampersand character only the string as far as the & character gets inputted to the function. these parameters work fine name;address1;address2;addres3
3
5591
by: jodleren | last post by:
Hi Pretty simple, I am sure. I have a small JS script, which is function OpenSomething(input) { win3=window.open("some_file.php?info=" + input,"mywin","width=500,height=600,scrollbars=yes,resizable=yes"); return false; }
4
4209
by: Kiran Makam | last post by:
I am setting the content of a div dynamically using innerHTML property. If the content contains an ampersand, text after the ampersand is disappearing in IE6. It works properly in Firefox. This is my code: ---------------- <body> <div id='div1'></div> <script>
0
8357
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
8803
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8700
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8581
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...
0
5612
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
4144
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...
1
2701
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
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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.