Skip to content

Instantly share code, notes, and snippets.

@Juhlinus
Created February 4, 2019 07:13
Show Gist options
  • Save Juhlinus/9d3d62e99f0f090d9057dc4b36cb9b88 to your computer and use it in GitHub Desktop.
Save Juhlinus/9d3d62e99f0f090d9057dc4b36cb9b88 to your computer and use it in GitHub Desktop.

Examples

$faker->numbersThatEquatesTo(100)

array:6 [
  0 => 6
  1 => 80
  2 => 5
  3 => 7
  4 => 1
  5 => 1
]
array:6 [
  0 => 72
  1 => 20
  2 => 4
  3 => 2
  4 => 1
  5 => 1
]
array:3 [
  0 => 78
  1 => 20
  2 => 2
]

If you already have a set of numbers that you want to be included, then you may pass them as the second argument in an array.

$faker->numbersThatEquatesTo(100, [0, 2, 4])

return examples with second parameter:

array:7 [
  0 => 0
  1 => 2
  2 => 4
  3 => 69
  4 => 15
  5 => 9
  6 => 1
]
array:10 [
  0 => 0
  1 => 2
  2 => 4
  3 => 36
  4 => 37
  5 => 6
  6 => 5
  7 => 7
  8 => 2
  9 => 1
]
array:9 [
  0 => 0
  1 => 2
  2 => 4
  3 => 8
  4 => 55
  5 => 18
  6 => 4
  7 => 8
  8 => 1
]

Min/Max Options

I decided to add a min/max options.

$faker->numbersThatEquatesTo(10, [], 1, 2)

array:6 [
  0 => 2
  1 => 2
  2 => 2
  3 => 1
  4 => 2
  5 => 1
]

$faker->numbersThatEquatesTo(30, [], 1, 6)

array:8 [
  0 => 4
  1 => 2
  2 => 6
  3 => 4
  4 => 4
  5 => 3
  6 => 5
  7 => 2
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment