php 带有数字和空格的变量回显不正确

php variable with numbers and white spaces echoing incorrectly

我有一个包含这个全局的页面:

$sampleIssue = array('vol'=>25,'no'=>3 and 4);

在另一页上,我有这样的代码 returns a 1 -?????怎么了?我确信这很简单,但我是新手 php 不知道。我在变量和字符串中搜索了空格,但仍然找不到答案。

echo $sampleIssue['no'];

改变

$sampleIssue = array('vol'=>25,'no'=>3 and 4);

$sampleIssue = array('vol'=>25,'no'=>'3 and 4');

"3 and 4" 是一个字符串。你必须把它放在引号里。 25不会显示任何问题,因为它是一个数字

$sampleIssue = array('vol'=>25,'no'=>3 and 4);

你需要一些关于 3 和 4 的引号,比如

$sampleIssue = array('vol'=>25,'no'=>'3 and 4');

不带引号的表达式 3 and 4 计算结果为 Are both the number 3 and the number 4 "true"?,这本身是正确的。如果您回显 PHP 布尔值 true,它显示为“1”。