itazev Posted April 11, 2007 Share Posted April 11, 2007 Hey guys! I often have seem these ( => , -> ) operators through php samples on the net but I do not know what they really do and i tried a search but they are so 'small' that it never give the results for them. particulary i note the use of => on foreachs. what does these operators do actually? cheers! Link to comment https://forums.phpfreaks.com/topic/46612-solved-and-operators/ Share on other sites More sharing options...
per1os Posted April 11, 2007 Share Posted April 11, 2007 They are essentially an association. Usually used in array (IE the foreach). When creating an associative array you use those to define a value at key. IE: $array = array("key1" => "Value1", "Key2" => "Value2"); print $array["key1"]; // will print Value1 foreach ($array as $key => $value) { print "Key: " . $key . " is Value: " . $value; } Hope that helps. Link to comment https://forums.phpfreaks.com/topic/46612-solved-and-operators/#findComment-226931 Share on other sites More sharing options...
kenrbnsn Posted April 11, 2007 Share Posted April 11, 2007 "=>" is used with arrays. "->" is used with classes (OOP). Ken Link to comment https://forums.phpfreaks.com/topic/46612-solved-and-operators/#findComment-226933 Share on other sites More sharing options...
boo_lolly Posted April 11, 2007 Share Posted April 11, 2007 let's cover one at a time. '=>' can be used in a couple of different ways. for instance in an associative array like this: $assoc = array('something' => 'something_else', 'dirka' => 'nation'); it can also be used in a foreach loop: foreach($assoc as $key => $val){ echo $key ." | ". $val ."<br />\n"; } it can also be used to compare two values: if($one >= $the_other || $the_other <= $one){ /*do something*/ } the '->' operator is generally used in object oriented programming. for instance: class Foo { var $foo; var $bar; function setBar ($bar) { $this->bar = $bar; } function getBar () { return $this->bar; } } $obj = new Foo; $obj->setBar('string'); look in my signature under 'oop' for more information on this. Link to comment https://forums.phpfreaks.com/topic/46612-solved-and-operators/#findComment-226935 Share on other sites More sharing options...
only one Posted April 11, 2007 Share Posted April 11, 2007 in most programming languages you find this =>(>=) = equal or greater than <=(=<) = equal or less than == = the same value as != = not the same value as -> is to do with oop Link to comment https://forums.phpfreaks.com/topic/46612-solved-and-operators/#findComment-226952 Share on other sites More sharing options...
itazev Posted April 11, 2007 Author Share Posted April 11, 2007 Thank you all indeed! All answers helped a lot! I think I'll really get the point when i starting making use of arrays. But i got the concept, that is important. Cheers! Link to comment https://forums.phpfreaks.com/topic/46612-solved-and-operators/#findComment-226955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.