So we got this function in PHP
strcmp(string $1,string $2) // returns -1,0, or 1;
We Do not however, have an intcmp(); So i created one:>
At a glance, yes it feels dirty. Except there must be a good reason you wrote that instead of just using the actual ==
, >
, and <
operators. What was the motivation for creating this function?
If it were me, I'd probably just do something like:
$x = $a==$b ? 0 : ($a>$b ? 1 : ($a<$b ? -1 : null));
I realize this is just as ugly, and the : null;
- not sure if PHP requires it or if I could have just done :;
but I don't like it and that code should never execute anyway... I think I'd be a lot less confused about this if I knew the original requirements!