/    Sign up×
Community /Pin to ProfileBookmark

What do "=>" and "->" mean?

I’ve started learning PHP, and I have run across these (operators???) before, but never an explanation of them. I have tried to search for them, but they always return no results, because they can’t be used as keywords, apparently. Anyway, I’ve seen them in the context,

[CODE]Array([0]=>1, [1]=>3)[/CODE]

and

[CODE]$rollovers->types(ROLLOVER_MOUSEOVER|ROLLOVER_MOUSEOUT)[/CODE]

I guess by the context that => is sort of like a literal, =, but why not use =??? And -> I’m guessing is a way of applying a method to an object? Anyway, could someone explain this to a newbie? Thanks!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@DahwanFeb 06.2009 — The -> operator accesses the fields of an instanced class. Here is an example.
<i>
</i>&lt;?php
$fckEditor = new FCKeditor('FCKeditor1');
$fckEditor-&gt;BasePath = "/fckeditor/";
$fckEditor-&gt;Value = 'Hi, this is an &lt;b&gt;Example&lt;/b&gt;';
$fckEditor-&gt;Height = 400;
$fckEditor-&gt;ToolbarSet = 'MySet';
$fckEditor-&gt;Create();
?&gt;
Copy linkTweet thisAlerts:
@NogDogFeb 06.2009 — "->", as referred to above, is used in object-oriented PHP code to specify that the expression on the right is a member of the object on the left. If you know JavaScript, it is essentially the same as the "." operator in JS, such as in "document.write();".

"=>" is used in certain array-related constructs to specify an array index on the left and its value on the right, such as in:
[code=php]
$myArray = array(1 => 'one', 'name' => 'Bob');
foreach($myArray as $key => $value)
{
echo "$key = $value<br />n";
}
[/code]
Copy linkTweet thisAlerts:
@jamesbcox1980authorFeb 06.2009 — Great! Thanks to both of you, especially NogDog! Javascript I understand perfectly. And the array thing makes much more sense now. I guess that is more necessary when you're not setting an array starting at the first field. Thanks guys!
×

Success!

Help @jamesbcox1980 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...