Jump to content

What is the => Operator?


utahcon

Recommended Posts

Ok I am looking through some code... so I need to know something.

I see this in my code

[code]
$SESSION['variable']->user->ID
[/code]

Is this calling the user ID for the $SESSION['variable']?

Also what does this do

[code]
$_SESSION['variable']->user->ID as $site_ID => $site_info
[/code]

Thanks!
Link to comment
Share on other sites

ok, the pointer (->) operator is completely different from the "=>" operator. the second is mainly used with arrays. it shows the relationship between a key and its value. for instance, if we were assigning an associative array, we would do something like this:
[code]
$favorites = array("candy" => "chocolate", "color" => "blue");
[/code]

this then assigns the value of "chocolate" to $favorites["candy"] and so forth.

you use the same operator when you're pulling information OUT of an array:
[code]
foreach ($favorites as $key => $value) {
  echo "$key contains \"$value\"<br />\n";
}
[/code]

as for the pointer (->) operator, you need to read up on OOP (Object Oriented Programming) to get a full realization of what all is involved with something like that.

hope this helps!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.