php short_open_tag显示html标签,而

问题描述 投票:0回答:1

我声明了以下数组

$book = [
'title' => "The Hitchhiker's Guide to the Galaxy",
'author' => 'Douglas Adams',
'description' => 'a comedy sci-fi adventure originally based on a BBC radio series'];

我把这个数组称为h1 html标签

<h1><?= "{$book['title']} by {$book['author']}"; ?></h1>

如果我使用<?php ... ?>代替,那么数组的内容不会出现。

php short-open-tags
1个回答
2
投票

这是因为<?=标签与<?php echo等同。这意味着它直接回应您的内容。如果你使用<?php,你必须调用echo函数来显示你的内容。

基本上:

<h1><?= "{$book['title']} by {$book['author']}"; ?></h1>

等于

<h1><?php echo "{$book['title']} by {$book['author']}"; ?></h1>
© www.soinside.com 2019 - 2024. All rights reserved.