新聞中心
想用php將數(shù)據(jù)庫里的內(nèi)容存為如下數(shù)組,求怎么寫?
while($row?=?mysql_fetch_array($result))
襄州網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站開發(fā)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)建站從2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。
{
$area_array[$row['area_id']]=array(?'area_name'?=?$row['area_name'],?'area_parent_id'?=?$row['area_parent_id']);
}?
print_r($area_array);
php用fopen,fwrite,fclose等函數(shù)將數(shù)據(jù)寫入文本文件后,如何儲(chǔ)存該數(shù)據(jù)?
fopen打開文件資源的時(shí)候,mode參數(shù)選擇w,w+或a,a+,如果文件不存在,就會(huì)自動(dòng)創(chuàng)建文件
一般情況建議直接使用file_put_contents,會(huì)自動(dòng)打開文件資源,寫入數(shù)據(jù)并關(guān)閉資源,如果文件不存在會(huì)自動(dòng)創(chuàng)建文件,操作也會(huì)簡便很多
詳細(xì)信息請參看文檔
php怎么按行保存數(shù)據(jù)到txt
$name = addslashes(stripslashes($_POST['name']));//主要是反轉(zhuǎn)義用戶輸入的個(gè)別轉(zhuǎn)義字符,然后統(tǒng)一轉(zhuǎn)義;
$password = $_POST['pwd'];
$content = $name."\t".$password."\r\n";
$f = fopen('test.txt', 'a+');//我猜測你應(yīng)該是想累加存儲(chǔ),在文件的結(jié)尾插入,所以用了fopen和a+,
fwrite($f, $content);
fclose($f);
在提取post中的之前,嚴(yán)謹(jǐn)點(diǎn)可以加上空值判斷
php怎么寫入、存儲(chǔ)數(shù)組數(shù)據(jù)?
PHP有自帶的高性能函數(shù) var_export
conn.php
?php
$dbconfig = array (
'host'='127.0.0.1',
'name'='root',
'password'='123456',
?
b.php
?php
// 讀取配置
include 'conn.php';
echo $dbconfig['host'];
// 修改配置
$dbconfig['host'] = 'xxx.xxx.xxx.xxx';
file_put_contents('conn.php', "?php\n$dbconfig = " . var_export($dbconfig) . "\n?");
// 再讀取配置
include 'conn.php';
echo $dbconfig['host'];
?
參考連接:
文章名稱:php存儲(chǔ)數(shù)據(jù)怎么寫 php保存
本文地址:http://fisionsoft.com.cn/article/dodgopp.html