我PHP和MySQL的初學者,我想分享一個劇本,我想從這裏另一個腳本訪問定義PHP數組是一個場景如何分享在PHP腳本陣列
script1.php
<?php
echo '<html>
<head></head>
<body>
<form action="script2.php" method="post" >
.......
....... some input
.......
<button >Submit</button>
</form>
</body>
</html>';
?>
script2.php
<?php
...........
...........
some validation
$age=array("Peter"=>"21","Ben"=>"45","Joe"=>"33");
some variable
$x = 'Peter'; $y= 'Ben';
// click on button run script3.
echo " <a href='script3.php?x=$x&y=$y'>
<button>Submit</button></a>";
?>
script3.php
<?php
// Though I tried both require_once and include, I can't access array 'age' in script2
require_once('script2.php');
include('script2.php');
// Here I am getting all variable defined in button part in actual code, but can't access array
post_r($_GET);
// Here I want to access array age in script2
?>
請注意,這不是實際的腳本,但這是我面臨的問題,我有索引文件,在第二個腳本中完成提交驗證後,表單被填充一次,如果驗證成功,則會立即顯示按鈕當我點擊按鈕腳本3將激活,在這裏我能夠接收在腳本中定義的變量,但我無法訪問在腳本2中定義的數組,雖然我一起嘗試以及單獨的這些函數require_once
和include
。如何共享數組?如何共享數組?請有人請給我你的一點時間,以便我可以學到一些東西......
查找PHP會話 – Steve