repl.it
@jonathanbell/

jayzisagoodrapper

PHP CLI

No description

fork
loading
Files
  • main.php
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

echo PHP_EOL;

// https://stackoverflow.com/a/39877269/1171790
function array_any(array $array, callable $fn) {
  foreach ($array as $value) {
    if($fn($value)) {
      return true;
    }
  }
  return false;
}

class Problem {
  protected $type;

  public function setType() {
    $types = [
      'foo',
      'bar',
      'bitch',
    ];

    $random_number = rand(1, 99);

    if ($random_number === 99) {
      $this->type = $types[2];
    } elseif ($random_number % 2 === 0) {
      $this->type = $types[0];
    } else {
      $this->type = $types[1];
    }
  }

  public function getType() {
    return $this->type;
  }
}

$problems = [];

for($i = 1; $i <= 99; $i++) {
  $problem = new Problem;
  $problem->setType();

  $problems[] = $problem;
  echo $problem->getType().' ';
}

function filterOutRecentlySpentFunds(array $problems, string $check = 'bitch') {
  $have_b = array_any($problems, function($problem) use ($check) {
    if ($problem->getType() === $check) {
      return true;
    }
  });

  $jayz_lyric = 'I got 99 problems'
    .($have_b ? ' and a B *is*' : ' but a B *ain\'t*')
    .' one!';

  return $jayz_lyric;
}

echo PHP_EOL;
echo PHP_EOL;
echo filterOutRecentlySpentFunds($problems);
echo PHP_EOL;
echo PHP_EOL;
Fetching token
?