To change the contents of test2.php, you need to use a code editor (or... thru file_put_contents (make sure your file is writable), or use a database approach to store the data values, etc.)
However, if you just want to change the value of the age element of the $data array thru programming, then you can use session variables to do what you want
So change test2.php to
<?php
session_start();
if (!isset($_SESSION["data"])) {
$_SESSION["data"]=array(
'name' => 'jack',
'age' => 8,
);
}
echo $_SESSION["data"]["age"];
?>
and use the following as test1.php
<?php
session_start();
//require_once "./test2.php";
//$data['age']=10;
//echo $data['age'];
$_SESSION["data"]["age"]=10;
echo "Data changed, please visit test2.php to see the effect";
?>
Please try these steps:
- visit the test2.php and see the value of $_SESSION["data"]["age"] echoed
- visit the test1.php (to change the data)
- visit test2.php and see what happens
test2.php? Why would that change, you'd need to edit/save/write new contents to the file.