我有以下問題。我有聲明的變量文件variable.php:變量不存在
<?php
$animal = "cat";
?>
和文件b.php,在這裏我想在一個函數
<?php
include_once 'a.php';
function section()
{
$html = "<b>" . $animal "</b>";
return $html;
}
?>
和文件c.php使用這個變量,其中我使用我的功能section()
<?php
require_once 'b.php';
echo section();
?>
我有一個錯誤信息,即variable $animal does not exist in file b.php
。爲什麼和我能在這裏做什麼?
最好的問候, 達格納
你曲解的錯誤。 –
變量作用域,$ animal是全局變量,不在section()的範圍內。 –
您能發佈確切的錯誤消息嗎? –