Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
2Fast2Nutricious
Oct 4, 2020

Like people said, array_map('trim', ...) is the most appropriate way to go.


Mind_Taker posted:

I'd just do a regex replace using preg_replace to get it done in a single line of code.

The regex you write to make sure you're not replacing multiple spaces in between characters would be a bit unwieldy, no?

Adbot
ADBOT LOVES YOU

2Fast2Nutricious
Oct 4, 2020

Maybe even this

code:

function pfft(int $roll, int $wealth): int {
    $range = fn ($max) => $roll <= $max;

    return (match(true) {
        $range(20) => [0, 0, 0, 0, 0], 
        $range(40) => [0, 0, 0, 1, 1], 
        $range(55) => [0, 0, 1, 2, 2], 
        $range(70) => [0, 1, 1, 2, 3], 
        $range(80) => [0, 1, 2, 2, 4], 
        $range(90) => [1, 1, 2, 3, 5], 
        $range(94) => [1, 2, 3, 3, 6], 
        $range(97) => [2, 3, 4, 4, 7], 
        $range(99) => [3, 4, 5, 6, 8], 
        $range(100)=> [4, 5, 6, 8,10]
    })[$wealth];
}
and this is why I get paid the big bucks :q:

code:

$my_eyes = fn(int $roll, int $wealth): int =>
 [
        [0, 0, 0, 0, 0], 
        [0, 0, 0, 1, 1], 
        [0, 0, 1, 2, 2], 
        [0, 1, 1, 2, 3], 
        [0, 1, 2, 2, 4], 
        [1, 1, 2, 3, 5], 
        [1, 2, 3, 3, 6], 
        [2, 3, 4, 4, 7], 
        [3, 4, 5, 6, 8], 
        [4, 5, 6, 8, 10]
    ][array_sum([
        $roll > 20,
        $roll > 40,
        $roll > 55,
        $roll > 70,
        $roll > 80,
        $roll > 90,
        $roll > 94,
        $roll > 97,
        $roll > 99,
    ])][$wealth];

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply