我声明了以下数组
$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 echo
等同。这意味着它直接回应您的内容。如果你使用<?php
,你必须调用echo函数来显示你的内容。
基本上:
<h1><?= "{$book['title']} by {$book['author']}"; ?></h1>
等于
<h1><?php echo "{$book['title']} by {$book['author']}"; ?></h1>