$ var和$ var。=之间的区别

时间:2013-08-14 04:10:47

标签: php

$var=$var.=之间的区别是什么?

我无法理解以下陈述之间的区别:

$querypost .= "&showposts=$limit";
$querypost .= "&paged=$paged";

3 个答案:

答案 0 :(得分:4)

这就是连接字符串,例如

$querypost = 'a';
$querypost = 'b'; // $querypost holds string 'b' now, 
                  // it will override the previous value


$querypost = 'a';
$querypost .= 'b'; // $querypost holds 'ab' now

如果你想要一个友好的解释,可以将.视为粘合剂,它会将两个字符串粘贴在一个变量中,而不是覆盖之前的变量。

在您的情况下,查询是连接的,通常程序员在查询字符串很大时执行此操作,或者当表单具有可选参数时通常连接它们...

答案 1 :(得分:0)

查看差异

<?php

$testing = "Test ";
$testing  = "file"; 

//if we print `$testing` output is `file` $testing overriding the previous value


$testing = "Test ";
$testing  .= "file";     

//if we print `$testing` output is `Test file`. because **.** is a concatenate the previous value
?>

例如在查询

$query  = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";

答案 2 :(得分:0)

  $var = "a"; ////results var is no a
  $var .= "b" ////results var is now ab .= is equal to concatanation of variable or string.