PHP 7 lan Operator Spaceship

Saliyane fitur anyar kayata hinting jinis kanggo jinis data skalar utawa kinerja sing dioptimalake , PHP 7 uga nggawa ekstensi basa sing migunani lan anyar. "Operator Spaceship" pungkasane mlebu ing jagad PHP (Programmer Ruby lan Perl wis ngerti suwene). \($a <=> $b\) ngasilake \(0\) yen lan mung yen kalorone operan padha, \(1\) yen sisih kiwa luwih gedhe lan \(-1\) .


Manut, operator anyar iki cocog karo fungsi signum \(sgn(xy)\) dingerteni saka matématika. Iki tegese operator bandhing sing ana uga bisa ditafsirake nganggo sintaks anyar:

\($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\)

Aturan sing padha ditrapake kanggo operator perbandingan (contone \([1,2,3] <=>[1,2,1]\) \(1\) ).

Bali