2 回答

TA貢獻(xiàn)1793條經(jīng)驗 獲得超6個贊
您可以使用serialize或json_encodePHP 函數(shù)來序列化數(shù)組數(shù)據(jù),然后以純文本形式存儲在文件中,如下所示:
$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 );
以上將以序列化的形式將數(shù)組存儲在 test.php 文件中。接下來是將這些數(shù)據(jù)讀取到您選擇的某個變量中。
$new_data = file_get_contents( 'test.php' );
$new_array = unserialize( $new_data );
$new_array現(xiàn)在已經(jīng)從外部文件加載了數(shù)組數(shù)據(jù)。希望這能解決問題。

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