Revision as of 11:32, 22 December 2007 editSmackBot (talk | contribs)3,734,324 editsm Standard headings &/or gen fixes. using AWB← Previous edit |
Latest revision as of 19:35, 28 July 2023 edit undoPsychpsyo (talk | contribs)14 editsm Made redirect more specificTag: Redirect target changed |
(38 intermediate revisions by 25 users not shown) |
Line 1: |
Line 1: |
|
|
#REDIRECT ] |
|
The '''spaceship operator''' is a binary ] that originated in the ] ]. Other languages, such as ] and ] also support the spaceship operator. It is written <=> . Unlike traditional equality operators, which will return 1 or 0 depending on whether the arguments are equal or unequal, the spaceship operator will return 1, 0, or -1 depending on the value of the left argument relative to the right argument. If the left argument is greater than the right argument, the operator returns 1. If the left argument is less than the right argument, the operator returns -1. If the two arguments are equal, the operator returns 0. |
|
|
|
|
|
|
|
{{Redirect category shell|1= |
|
The spaceship operator is primarily used for comparisons in ]. It is usable for a ] as it will return 0 for equal arguments. |
|
|
|
{{R to section}} |
|
|
|
|
|
{{R with history}} |
|
The spaceship operator takes its name because it looks like a small ] as ]. The term is now commonly used and the operator is referred by the name within the Perl ]. |
|
|
|
}} |
|
|
|
|
== Example == |
|
|
<source lang="php"> |
|
|
$a = 5 <=> 7; # $a is set to -1 |
|
|
$a = 7 <=> 5; # $a is set to 1 |
|
|
$a = 6 <=> 6; # $a is set to 0 |
|
|
</source> |
|
|
|
|
|
==External links== |
|
|
{{wikibooks|Perl Programming}} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
] |
|