php echo无法正确显示变量

php echo无法正确显示变量,php,Php,我正在尝试在我的网站上的一些页面上获得我需要的输出 在meta.php上,我有: <?php $title1 = "this is the title for this $address"; ?> <?PHP include('meta.php'); ?> <?php $address = "address one"; ?> 在index.php上,我有: <?php $title1 = "this is the title for this

我正在尝试在我的网站上的一些页面上获得我需要的输出

在meta.php上,我有:

<?php $title1 = "this is the title for this $address"; ?>
<?PHP include('meta.php'); ?>

<?php $address = "address one"; ?>

在index.php上,我有:

<?php $title1 = "this is the title for this $address"; ?>
<?PHP include('meta.php'); ?>

<?php $address = "address one"; ?>

部分:

<?php echo $title1; ?>

问题是输出没有显示
$address


我错过了什么

您的代码顺序错误

<?PHP include('meta.php'); ?>

<?php $address = "address one"; ?>

转化为

<?php $title1 = "this is the title for this $address"; ?>

<?php $address = "address one"; ?>


PHP代码自上而下执行;因此,当设置
$title1
时,
$address
还不存在,因此它不能用您想要的值替换它。

您的第一行替换执行时的
$address
。它将成为一根弦。因此,在将变量包含在
$title
中之前,需要先设置变量

如果您先分配
$address
,然后分配include,它将起作用

<?php $address = "address one"; ?>
<?PHP include('meta.php'); ?> 

有趣的是,有时候答案就在你眼前。在这里提问之前,我试着在php.net上阅读,并在谷歌上搜索了一个多小时。谢谢大家的提醒@Nanne:)