PDA

View Full Version : -> and =>??


Goldknight
09-29-2002, 02:34 AM
What is different between -> and =>?? Call me stupid if you will :)

I tried to find out more about that at php.net and books, no luck. I wonder can someone give me the examples the differences between -> and => and details about it if possible. Thanks.

Neo
09-29-2002, 08:26 AM
-> is used mostly in object oriented programming like

class Name {

var username;

function Start ($this->username) {

}

}

and

=> is equal or greater than

if (3=>10) {
// do this
}

Goldknight
10-01-2002, 12:41 AM
Thanks :) yours and Professional PHP4 by Wrox help me lots about this. It is OOP after all. Thanks

futureal
10-02-2002, 07:01 AM
Originally posted by Neo
=> is equal or greater than

if (3=>10) {
// do this
}

Actually, this is incorrect for PHP. The "greater than or equal" operator is >=, "less than or equal" is <=.

The => operator is something different entirely. It is most commonly used in a foreach control structure, such as:


foreach ($array as $key => $value) {
echo "Key: $key; Value: $value<br>\n";
}


The operator tells the interpreter to link each key/value pair from the array as a matching entity. This is commonly used to access a hash-table-type data structure.

nsr81
10-02-2002, 12:50 PM
It is also used to create an array using Array( ) language-construct.

http://www.php.net/manual/en/function.array.php


$a = array( 1 => 'one', 2 => 'two', 3 => 'three' );