[SOLVED] Where is the & symbol for in some functions?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

[SOLVED] Where is the & symbol for in some functions?

Post by WaldoMonster »

Sometimes I see functions like this:

Code: Select all

<?php
Function (&$some_value)
{
// Do something
}
?>
Where is the & symbol for?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

reference.. basically, $some_value will be a pointer, if you're familiar to that term, to the data passed. The function is able to directly modify the content of the data passed to it, so it could return lots of extended data..
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Is this the purpose of the reference?
Where can I find some more information about pointers and reference?

Code: Select all

<?php
function AddMonster(&$name)
{
$name .= 'Monster';
}

$name = 'Waldo';
AddMonster($name);
echo $name; //returns WaldoMonster
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's exactly the use. :)

:arrow: [php_man]references[/php_man]
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Thanks for the help.

Now it is comming back to me.
It works the same way as Turbo Pascal, that is a long time ago :wink:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

omg pascal........ the pain.

i remember in grade 10 i made slimmer :)
Post Reply