在included.php中使用变量的echo变量

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

我有两个PHP文件。一个是action.php,另一个是include.php

我需要在我的其他脚本中回显变量形式include.php。

include.php中基本上有这个变量

     $id= $web_id;
     $start = "Hello, ";
     $end = "works.";

在我的action.php中,我有这些变量

     $web_id = "testing echo from variable in include.php";

     echo $start; // variable is in include.php
     echo $id; //variable is in include.php
     echo $end; //variable is in include.php

结果是

     Hello, works.

我想要实现的是

     Hello, testing echo from variable in include.php works. 

这个语法只为$ id提供了空值。在包含文件中用变量回显变量的正确语法是什么?

php variables include echo
1个回答
1
投票

在进行包含之前,需要设置$web_id变量。看看这个例子:

action.php

$web_id = 'this'.
include 'include.php';

echo $start . $id . $end;

include.php

$id = $web_id;
$start = 'Hello ';
$end = ' works.';
© www.soinside.com 2019 - 2024. All rights reserved.