16
Skayo
6y

In PHP, this:
<?php
if($a < $b) {
$c = 'W';
} elseif($a > $b) {
$c = 'E';
} else {
$c = ' ';
}
?>

Does the same as this:
<?php
$c = ' WE'[$c<=>$a];
?>

How cool is that?!? xD

Comments
  • 3
    $c = ($a < $b) ? 'W' :

    ($a > $b) ? 'E' :

    ' ';

    This will produce 'E' unless a and b are equal. How broken is that!

    http://sandbox.onlinephpfunctions.com/...
  • 1
    Not very
  • 2
    Wow, php is ugly
  • 4
    Not very cool.. because you're implicitly casting boolean to int..
  • 2
    @inaba Well you can write ugly code in every language if you try hard enough..

    Not like anyone with their right mind would write production code like that.
  • 6
    Isn't it:

    <?php
    $c = ' WE'[$b<=>$a];
    ?>

    ? <== (Don't know where to put my question mark)

    Also PHP is ugly in my opinion, but I like using it :)
  • 5
    @TheOct0 I messed my shit up as well. Mismatched the order for $a and $b, and probably some other shit. I've never been good at optimizing code ^^'
  • 2
    What the fuck is that?! Kill it before it lays eggs! Kill it with fire!
  • 1
    c = (a>b?'E':a<b?'W':'') in any moderately competent language tho

    And in a good one
    let c = match a<b with | 1->'W' | 0->'' | -1->''E';;
  • 1
    <@TheOct0>
    Whoopsie yeah I mixed that up with the actual code I wrote for the Code Golf I did...
    As you said, it should be:

    $c = ' WE'[$b<=>$a];
  • 1
    It'll make whoever ends up maintaining your code hunt you down.. shit like this is unreadable and fucking annoying.
  • 2
    Ya guys! Hey guys, PHP sucks and Linux is awesome amirite?
  • 1
    This is why we can't have nice things
  • 2
    I am going to stick to

    $c = $a < $b ? 'W' : 'E';

    Unless the spaceship method allows for the else c = ' '
Add Comment