Jump to content

Archived

This topic is now archived and is closed to further replies.

utahcon

What is the => Operator?

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!

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

×

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.