Whay is ->

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
sonofbc
Forum Newbie
Posts: 3
Joined: Thu Nov 26, 2009 9:38 am

Whay is ->

Post by sonofbc »

I am a newbie trying to learn some PHP . I have been studying others code and I keep coming across what appears to be operators I do not recognize. There are 2 in particular that keep appearing. They are "->" and "=>".
Examples of the code.

$Test->setTest($myname);

(I could not find the code snippet of the other 'operator'. =>)

Can anyone help?

Thanks
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Whay is ->

Post by pickle »

-> is an operator used with objects. In your example, $Test is an object, that has a setTest() method.

=> is used with arrays. Off the top of my head, I can only recall it used in two place, when iterating through arrays in a foreach(), and when creating arrays:

Code: Select all

foreach($foo as $key=>$value)
{
  //do something
}
 
 
$myArray = array(
  'one'=>1,
  'two'=>2
);
In both cases, the => is used to denote the value associated with a key in an array.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
sonofbc
Forum Newbie
Posts: 3
Joined: Thu Nov 26, 2009 9:38 am

Re: Whay is ->

Post by sonofbc »

Thank you Pickle.. I finally found a 'object operator' tutorial once you pointed me in the right direction. I had gone completely though the standard PHP tutorial but no luck.

Thanks again.
Post Reply