// this code is somewhere on bottom of the page $-6ren">
gpt4 book ai didi

PHP:读取底部存在的顶部变量

转载 作者:行者123 更新时间:2023-12-02 01:22:34 24 4
gpt4 key购买 nike

有没有办法读取顶部定义在底部某个位置的变量。以下是此类情况的示例:

<!--this image is somewhere on top of the page-->
<img src="/<?php print logoPath(); ?>" border="0" />

// this code is somewhere on bottom of the page
$logo_query = "select logo_path from table where id = $row->user_id";
$res_logo = mysql_query($logo_query) or die(mysql_error());
$row_logo = mysql_fetch_object($res_logo);
$logo_path = $row_logo->logo_path;

function logoPath()
{
global $logo_path;
return $logo_path;
}

我尝试使用该函数返回值,但即使这样似乎也不起作用。

有什么解决办法吗?

谢谢

最佳答案

不,在 PHP 中,所有指令都是按顺序执行的,因此您无法读取尚 undefined variable 。您必须将设置 $logo_path 值的代码移至调用 logoPath() 函数的位置上方。

或者,您可以将 sql 代码放入 logoPath() 函数中,这样您就可以在调用该函数的位置下方使用返回 Logo 路径的函数。

关于PHP:读取底部存在的顶部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1859135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com