Jump to content

What does => mean?


dgruetter

Recommended Posts

i know that => is commonly used to extract a value for a key in an array...

 

$a = array(
    "one" => 1,
    "two" => 2,
    "three" => 3,
    "seventeen" => 17
);

foreach ($a as $k => $v) {
    echo "\$a[$k] => $v.\n";
}

 

something like that

Link to comment
Share on other sites

also as a condition

 

> means greater than

< means less than

= means the same as

so u can use

 

=< means equal to or less than

=> means equal to or more than

its a way of setting a dividing line

 

example

 

$a = '????';

$b = '10';

 

if ($a => $b)

$answer = ''yes;

else

$answear = 'no';

 

if $a is less than 10 then $b returns 'no'

if %a is 10 or more then $b returns 'yes'

Link to comment
Share on other sites

The => operator is, perhaps confusingly, called a "double arrow" (the token name that PHP sees is T_DOUBLE_ARROW).  It is used in two places, neither being anything directly related to objects or OOP.

 

[*]When assigning keys to be associated with array values

 

$fruits = array('a' => 'apple', 'b' => 'banana');

 

 

[*]When retrieving the key in a foreach loop

 

foreach ($fruits as $key => $value) {

 

Link to comment
Share on other sites

The => operator is, perhaps confusingly, called a "double arrow" (the token name that PHP sees is T_DOUBLE_ARROW).  It is used in two places, neither being anything directly related to objects or OOP.

 

[*]When assigning keys to be associated with array values

 

$fruits = array('a' => 'apple', 'b' => 'banana');

 

 

[*]When retrieving the key in a foreach loop

 

foreach ($fruits as $key => $value) {

 

 

Very defined formulation! How would you define -> ? When using for example $this->post_id

 

I know how to use it but I don't really know how to define or explain it to somebody, and I think that shows that I don't fully understand it.

 

 

Link to comment
Share on other sites

Very defined formulation! How would you define -> ?

 

That is the "object operator" or, more colloquially, the "arrow operator".  Its token name when PHP parses your code into pieces is T_OBJECT_OPERATOR.

And in which situations exactly is it used?

When you're using/assigning an objects properties/methods. Its all in the manual.

Link to comment
Share on other sites

salathe copy paste from php.net  ;)

 

Not at all, though I do know the manual inside out.

 

Yeah, well there's a good chance that salathe may have actually written that part of the manual.

 

Not that particular part. :)

 

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.