php fzaninotto Faker - 如何只生成5位邮编?

时间:2015-12-13 23:49:41

标签: php zipcode postal-code faker

有没有办法使用fzaninotto's Faker生成5位邮政编码/邮政编码?

他提供的功能,$faker->postcode,不提供限制其大小的参数,因此它通常提供9位数的邮政编码而不是5,例如,10278-4159而不是10278.这是有问题的用于播种数据库,因为我的sql数据库的zipcode列为INT(5)。

我知道我可以使用Faker生成随机的5位数字,但我想知道是否存在生成5位数邮政编码的本地方式。

1 个答案:

答案 0 :(得分:3)

我找到的解决方法使用地址类的邮政编码,该邮政编码总是返回5位数。

而不是$faker->postcode,您可以拨打Address::postcode()

不要忘记包含use Faker\Provider\Address;