PHP打印错误


PHP printing something wrong

我有以下php行:

<?php echo "?page=" . $selectedImage + 1 ."&pid=5"."&type=". $type . "&special=" . $special; ?>

上面的线在内

生成的链接为:

XXXXXX.com/1&pid=5&type=AD23&special=第一个

而且它没有打印"?page",知道为什么吗?

提前感谢!

尝试添加括号

<?php echo "?page=" . ($selectedImage + 1) ."&pid=5"."&type=". $type . "&special=" . $special; ?>

奇怪的行为…:(但要修复它,请尝试以下操作:

<?php echo "?page=" . (string)($selectedImage + 1) ."&pid=5" . "&type=" . $type . "&special=" . $special; ?>

格式化字符串的最佳实践是使用sprintf()

sprintf("?page=%d&pid=5&type=%s&special=%s", ($selectedImage + 1), $type, $special);

编辑

Mystery Resolved 
/*
 PHP will try to create number by concatening the string '20' and the integer
 $i, so the operation will result to the integer 205
 after that, make addition operation => 210 
*/
$i = 5;
echo '20' . $i + 5;  

在您的案例中发生的情况类似:)