This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
当我回显var_dump($ _ variable)时,我得到一条长的包装线,包含所有的varable和值
["kt_login_user"]=> string(8) "teacher1" ["kt_login_id"]=> string(3) "973" ["kt_campusID"]=> string(4) "9088" ["kt_positionID"]=> string(1) "5"
Run Code Online (Sandbox Code Playgroud)
有没有办法让每个值都显示在自己的行上以便于阅读?像这样的东西:
["kt_login_user"]=> string(8) "teacher1"
["kt_login_id"]=> string(3) "973"
["kt_campusID"]=> string(4) "9088"
["kt_positionID"]=> string(1) "5"
Run Code Online (Sandbox Code Playgroud) 我刚发现了一些东西.
echo $var1 , " and " , $var2;
Run Code Online (Sandbox Code Playgroud)
是相同的:
echo $var1 . " and " . $var2;
Run Code Online (Sandbox Code Playgroud)
什么是PHP中的实际字符串连接运算符?我应该使用.还是,?
假设我有两个 PHP 语句:
echo "foo"."bar"
echo "foo", "bar"
Run Code Online (Sandbox Code Playgroud)
请注意连接字符串的不同方式 - 使用 a.或 a ,。
我意识到这两种方法之间的实际差异, using,为关键字提供了多个参数echo,而 using.实际上在 ing 之前将字符串连接在一起echo。
但我的问题是,哪种方式更快?
有人可以告诉我为什么我的php行不能正常工作(回声)?
我知道我可以用不同的方式编写代码来使换行工作,但我想知道这背后的原因吗?
<?php
$var1 = 3;
echo "Addition = " . $var1 += 3 . "<br>";
echo "Subtraction = " . $var1 -= 3 . "<br>";
echo "Multiplication = " . $var1 *= 3 . "<br>";
echo "Division = " . $var1 /= 3 . "<br>";
?>
Run Code Online (Sandbox Code Playgroud) 我在旧平台上使用PHP 5.3中的ImageMagick.我偶然发现了一段代码,这些代码在变量周围使用圆括号时无效,但在删除这些括号时确实有效.变量周围的括号有什么作用?
$im = new imagick();
$im->readImageBlob($photo);
$im->setImageFormat('jpg');
$photo = ($im);
Run Code Online (Sandbox Code Playgroud)
它没有用这段代码读取图像数据,但是当我删除括号时它就这样做了.
$photo = $im;
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?