Re: Inline switch as alternative to nested inline conditional

From: Date: Wed, 16 Oct 2019 13:58:16 +0000
Subject: Re: Inline switch as alternative to nested inline conditional
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-107558@lists.php.net to get a copy of this message
> > <?php > > $say = switch (date("w")) { > > case 0 => "weekend!"; > > case 1, 2, 3, 4, 5 => "weekday :("; > > case 6 => "weekend!"; > > }; > > echo "Today is {$say}"; If you had a really long expression, it may be easier to read if the assignment was moved to the end, perhaps like this: switch (date("w")) { case 0 => "weekend!"; case 1, 2, 3, 4, 5 => "weekday :("; case 6 => "weekend!"; // lots more cases ... } => $say; echo "Today is {$say}";

« previous php.internals (#107558) next »