I-PHP 7 kanye ne-Spaceship Operator

Ngokungeziwe kuzici ezintsha njengokuthayipha kohlobo lwezinhlobo zedatha ye-scalar noma ukusebenza okuhle , i-PHP 7 nayo iletha izandiso zolimi eziningi ezintsha, eziwusizo nayo. I- "Spaceship Operator" ekugcineni isingenise emhlabeni we-PHP (abenzi bohlelo bakaRuby noPerl bayazi isikhathi eside). \($a <=> $b\) ibuyisa \(0\) uma futhi kuphela uma womabili ama-opharetha elingana, \(1\) uma elakwesobunxele likhulu futhi \(-1\) ngenye indlela.


Ngokunjalo, lo opharetha omusha uhambelana nomsebenzi wesiginali \(sgn(xy)\) owaziwa ngezibalo. Lokhu kusho ukuthi ama-opharetha akhona wokuqhathanisa nawo angahunyushwa kusetshenziswa i-syntax entsha:

\($a < $b\) \(($a <=> $b) === -1\)
\($a <= $b\) \(($a <=> $b)\) !\(== 1\)
\($a == $b\) \(($a <=> $b) === 0\)
\($a\) !\(= $b\) \(($a <=> $b)\) !\(== 0\)
\($a >= $b\) \(($a <=> $b)\) !\(== -1\)
\($a > $b\) \(($a <=> $b) === 1\)

Imithetho efanayo iyasebenza ngokuqondene nabaqhubi bokuqhathanisa (isibonelo \([1,2,3] <=>[1,2,1]\) kulingana \(1\) ).

Emuva