我正在使用php函數文件來設置全局變量的值,但是當我在其他php文件中使用include調用函數時忽略了該值(「functions.php 「);如何在調用php函數期間保持變量值
我這樣做:
////File1.php////
include("functions.php");
$data_person = $_POST['data_person'];//here i am getting 'data_person' from a form, it works fine
receive_DP($data_person);//Here I send the variable
show_DP();//It shows the values inside $data_person
////functions.php////
$data_person;
function receive_DP($data_person_array)
{
global $data_person;
$data_person = $data_person_array;
}
function show_DP()
{
global $data_person;
echo "name:".$data_person[0];
echo "last name:".$data_person[1];
echo "age".$data_person[2];
}
//then i go to File2.php with a FORM (input submit) and i need to keep the values in $data_person
//It is like a header, It shows personal info, It is supposed to be the values of this variable
//are set and they should be always
////File2.php//// HERE IS THE PROBLEM, I MISSED THE VALUES OF $data_persona
include("functions.php");
show_DP();//It shows nothing, just name:, last name: and age:, but not the the values
就像我說我來自一個表單標籤獲得的值,那麼我將它們傳遞給File1.php與$ _ POST得到的值,它工作正常,我調用了這兩個函數(receive_DP()和show_DP()),並且它的工作正常,接下來我使用按鈕去File2.php,但是當我調用show_DP()函數時,值都消失了。
在會話中存儲您的價值,比你可以訪問他們任何你想要的地方 – 2014-09-27 04:52:55
我想到了這一點,但我不知道如何使用$ _SESSION(),請快速解釋我應該怎麼做,謝謝 – 2014-09-27 04:54:25
在哪個文件中獲取值,以及您想要訪問哪個文件。謝謝回覆我我會告訴你 – 2014-09-27 04:55:22