$_SESSION['result'] = '2011-08-14 20:34:12';
echo $dateTime = "$_SESSION['result'] +1 hour";
预期输出:'2011-08-14 20:34:12 +1 小时'
我知道双引号有错误,但不知道如何解决。谁能帮我吗?真的很感谢有人能给出一些解释,谢谢!
$_SESSION['result'] = '2011-08-14 20:34:12';
echo $dateTime = "$_SESSION['result'] +1 hour";
预期输出:'2011-08-14 20:34:12 +1 小时'
我知道双引号有错误,但不知道如何解决。谁能帮我吗?真的很感谢有人能给出一些解释,谢谢!
$_SESSION['result'] = '2011-08-14 20:34:12';
$dateTime = "{$_SESSION['result']} +1 hour";
echo($dateTime);
用这个:
$dateTime = "{$_SESSION['result']} +1 hour";
或这个:
$dateTime = $_SESSION['result'] . " +1 hour";
接着
echo($dateTime);
您可以连接字符串
echo $dateTime = $_SESSION['result']." +1 hour";
我建议您阅读PHP 文档中的字符串。您在这里想要的称为串联。
$_SESSION['result'] = '2011-08-14 20:34:12';
$dateTime = $_SESSION['result'] . ' +1 hour';
echo $dateTime;
$dateTime
还要注意设置内容后要回显的最后一行。
您可以在 PHP 中找到许多如何访问数组元素的示例:Array - Array do's and don'ts。
$arr = array('foo'=>1234, 'bar'=>array('baz'=>'abcdef'));
// simply no quotes within double-quoted string literals
echo "foo: $arr[foo]\n";
// echo "foo: $arr[bar][baz]\n"; <- doesn't work as intended
// curly-braces -> same syntax as outside of a string literal
echo "foo: {$arr['foo']}\n";
echo "foo: {$arr['bar']['baz']}\n";
// string concatenation
echo "foo: ". $arr['foo'] ."\n";
echo "foo: ". $arr['bar']['baz'] ."\n";
// printf with placeholder in format string
printf("foo: %s\n", $arr['foo']);
printf("foo: %s\n", $arr['bar']['baz']);
// same as printf but it returns the string instead of printing it
$x = sprintf("foo: %s\n", $arr['foo']);
echo $x;
$x = sprintf("foo: %s\n", $arr['bar']['baz']);
echo $x;
$_SESSION['结果'] = '2011-08-14 20:34:12';
回声 $dateTime = $_SESSION['result'] 。“+1 小时”;
试试上面的。
在您的情况下,对字符串使用单引号,对变量使用任何内容。
echo $dateTime = $_SESSION['result'].' +1 hour';