Jump to content


&$ in a function declaration

  • Please log in to reply
2 replies to this topic

#1 Marrvel

  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationLondon

Posted 13 October 2006 - 03:30 PM

Hello everybody,

I'm working on a credit card validation but that's not important. While looking at some other peoples scripts for inspiration I found on with this syntax in the function declaration:

checkCreditCard ($cardnumber, $cardname, &$errornumber, &$errortext)

all i want to know is why  are there &'s in front of the last 2 variables? what does it do? I've never seen it used before.


#2 JayBachatero

  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationQueens NY

Posted 13 October 2006 - 03:57 PM

It's called pass by reference.
SMF Developer && Converter Specialist

#3 fezzik

  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 13 October 2006 - 03:58 PM

The ampersand means that the value of the variable is being assigned by reference. I use the same CC function you posted. I also had the same question when I stumbled across the ampersand. Below is the link to my previous post which explains the "assign by reference" and how to use it with this function. In addition, I also posted the link to the php manual that explains variables.

my previous post - http://www.phpfreaks...c,110130.0.html

php manual - http://us3.php.net/language.variables



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users