2 回答

TA貢獻1793條經驗 獲得超6個贊
您可以使用serialize或json_encodePHP 函數來序列化數組數據,然后以純文本形式存儲在文件中,如下所示:
$data = array(
[0] => "1,2,3,4,5",
[0] => "1,2,4,3,2",
[0] => "1,22,73,49,5",
[0] => "1,9,8,2,1",
);
$data = serialize( $data );
file_put_contents( 'test.php' , $data );
以上將以序列化的形式將數組存儲在 test.php 文件中。接下來是將這些數據讀取到您選擇的某個變量中。
$new_data = file_get_contents( 'test.php' );
$new_array = unserialize( $new_data );
$new_array現在已經從外部文件加載了數組數據。希望這能解決問題。

TA貢獻1859條經驗 獲得超6個贊
如果我清楚地理解你,你只需要在 test2.php 中包含 test.php
//In test2.php you have:
<?php
include 'test.php';
以上將使數組在 test2.php 中可訪問
同時,我懷疑數組是否有效我相信你最好將它存儲為變量,或者更好地為數組命名,其索引反映了上面的變量名稱。
你到底想做什么?
- 2 回答
- 0 關注
- 154 瀏覽
添加回答
舉報