Page 1 of 1
Whay is ->
Posted: Thu Nov 26, 2009 9:46 am
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
Re: Whay is ->
Posted: Thu Nov 26, 2009 9:56 am
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.
Re: Whay is ->
Posted: Thu Nov 26, 2009 10:17 am
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.