0

$var=和 和有什么不一样$var.=

我无法理解以下语句之间的区别:

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

3 回答 3

4

这是连接字符串,例如

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


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

如果您想要一个友好的解释,.请将其视为胶水,它将两个字符串粘在一个变量中,而不是覆盖以前的字符串。

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

于 2013-08-14T04:12:54.533 回答
0
  $var = "a"; ////results var is no a
  $var .= "b" ////results var is now ab .= is equal to concatanation of variable or string.
于 2013-08-14T06:06:10.383 回答
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";
于 2013-08-14T04:32:13.507 回答