PHP在1个变量中存储多个整数变量? [英] PHP storing multiple integer variables in 1 variable?

查看:123
本文介绍了PHP在1个变量中存储多个整数变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个php脚本,它创建一个长度为7位且不包含0的随机数,唯一的问题是我必须调用函数rand 7次并存储在a中生成的每个数字不同的变量,但我想知道如何将这些数字放在变量中而不是将它们加在一起

I'm creating a php script which creates a random number which is 7 digits long and doesn't contain 0's, the only problem with this is that I have to call the function rand 7 times and store every number generated in a different variable, but I was wondering how I could put these numbers together in a variable instead of adding them together

$ security_number = $ 1&& $ 2&& $ 3等等。

$security_number = $1&&$2&&$3 and so on.

提前感谢。

推荐答案

我想我知道你想要实现的目标。你需要一种你真正想要七个字符的数字串的心态。例如,如果您的号码是0028172,如果它被存储为数字,那么就像数字计算器一样,它将显示为28172,除非您使用字符串格式。

I think I know what you are trying to achieve. You need the mindset that you actually want a seven character string of digits. For example, if your number was 0028172, if it is stored as a number then just like a digital calculator it will be displayed as 28172 unless you use string formatting.

如果你已经有代码创建个别数字,只需使用连接:

If you already have code creating the individual digits, simply use concatenation:

$ securitycode = $ digit1。 $ digit2。 $ digit3。 $ digit4。 $ digit5。 $ digit6。 $ digit7;

$securitycode = $digit1 . $digit2 . $digit3 . $digit4 . $digit5 . $digit6 . $digit7;

希望这可以帮到你。

这篇关于PHP在1个变量中存储多个整数变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆