[英]Can i change the value of local variable sitting inside the function in PHP?
[英]How can I change the value of a variable inside an if statement in PHP?
我正在嘗試更改 if 語句中 PHP 變量的值。
我的主文件如下所示:
include_once '/css/colors.php';
// Check if contrast mode is on
if($_GET['cm'] == 1){
$priColor = '#333';
}
我的 colors.php 文件如下所示:
$priColor = '#fff';
我的請求看起來像這樣順便說一句:
index.php?cm=1
我知道正在訪問 if 語句,因為如果我輸入echo: 'test';
它在文檔中說test
。
看起來我無法更改在另一個文檔中聲明的 if 語句中的變量。 但為什么? 什么是可能的解決方案?
提前致謝! ^^
最好的方法是通過 jquery 更改 css 屬性,它會是這樣的:
echo <script>$("#example").css("color", "red")</script>;
或者,如果您想通過 php 執行,則必須設置變量 global,如下所示:
$GLOBALS['priColor'] = '#333';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.