Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Update optional() in readme to use v2 weight #2068

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,15 @@ for ($i = 0; $i < 10; $i++) {
print_r($values); // [1, 4, null, 9, 5, null, null, 4, 6, null]

// optional() accepts a weight argument to specify the probability of receiving the default value.
// 0 will always return the default value; 1 will always return the provider. Default weight is 0.5 (50% chance).
$faker->optional($weight = 0.1)->randomDigit; // 90% chance of NULL
$faker->optional($weight = 0.9)->randomDigit; // 10% chance of NULL
// 0 will always return the default value and 100 will always return the provider.
// Default weight is 50 (50% chance).
$faker->optional($weight = 10)->randomDigit; // 90% chance of NULL
$faker->optional($weight = 90)->randomDigit; // 10% chance of NULL

// optional() accepts a default argument to specify the default value to return.
// Defaults to NULL.
$faker->optional($weight = 0.5, $default = false)->randomDigit; // 50% chance of FALSE
$faker->optional($weight = 0.9, $default = 'abc')->word; // 10% chance of 'abc'
$faker->optional($weight = 50, $default = false)->randomDigit; // 50% chance of FALSE
$faker->optional($weight = 90, $default = 'abc')->word; // 10% chance of 'abc'

// valid() only accepts valid values according to the passed validator functions
$values = array();
Expand Down