这有什么用。变量php末尾的运算符
我在这有什么用。变量php末尾的运算符,php,operator-keyword,Php,Operator Keyword,我在http://in3.php.net/manual/en/function.chr.php <?php function randPass($len) { $pw = ''; //intialize to be blank for($i=0;$i<$len;$i++) { switch(rand(1,3)) { case 1: $pw.=chr(rand(48,57)); break; //0-9 case 2: $pw.
http://in3.php.net/manual/en/function.chr.php
<?php
function randPass($len)
{
$pw = ''; //intialize to be blank
for($i=0;$i<$len;$i++)
{
switch(rand(1,3))
{
case 1: $pw.=chr(rand(48,57)); break; //0-9
case 2: $pw.=chr(rand(65,90)); break; //A-Z
case 3: $pw.=chr(rand(97,122)); break; //a-z
}
}
return $pw;
}
?>
Example:
<?php
$password = randPass(10); //assigns 10-character password
?>
例子:
能否请您解释一下
在$pw
之后的
的用法或效果。我试图寻找类似的问题,但没有找到。如果有任何相关问题,请提供链接
谢谢连接运算符
$a = "Hello ";
$a .= "World!";
// $a = Hello World!
$a = "Hello ";
$b = "there ";
$c = "stack ";
$d = "overflow ";
$a .= $b;
$a .= $c;
$a .= $d;
echo $a;
// $a = Hello there stack overflow
是字符串连接
$a = 'hello';
$b = 'there';
然后
印刷品
hellothere
它用于连接。
当您像这样使用它时,
=
它连接值。$str = '';
$str .= 'My ';
$str .= 'Name ';
$str .= 'Is ';
$str .= 'Siamak.';
echo $str;
输出为:我的名字是Siamak。
在其他情况下,例如在循环中:
$str = '';
$i=0;
while($i<10)
{
$str .= $i;
$i++;
}
echo $str;
$str='';
$i=0;
而我
同:
$a = 'hello';
$a = $a . ' world';
=
只需添加您必须将代码读为$pw.=chr(…);
=
是一个运算符。请参阅:这是一种生成随机密码的可怕方式。为什么否决票/无注释?这绝对正确。的确。这不仅是第一个答案,也是正确的。也许您应该标记它(如果否决票来自另一位答案作者,这是不公平的)
$a = 'hello';
$a .= ' world';
$a = 'hello';
$a = $a . ' world';
$a = "Hi!";
$a .= " I";
$a .= " am";
$a .= " new";
$a .= " to";
$a .= " PHP & StackOverflow";
echo $a;
//echos Hi! I am new to PHP & StackOverflow