數(shù)據(jù)庫提到的數(shù)據(jù)一般是資源類型的,要逐一讀出,添加到數(shù)組
專業(yè)從事網(wǎng)站制作、成都網(wǎng)站設計,高端網(wǎng)站制作設計,成都小程序開發(fā),網(wǎng)站推廣的成都做網(wǎng)站的公司。優(yōu)秀技術團隊竭力真誠服務,采用成都h5網(wǎng)站建設+CSS3前端渲染技術,響應式網(wǎng)站,讓網(wǎng)站在手機、平板、PC、微信下都能呈現(xiàn)。建站過程建立專項小組,與您實時在線互動,隨時提供解決方案,暢聊想法和感受。
while($row = mysql_fetch_assoc($res)){
$data[] = $row;
}
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'];
?
參考連接:
遍歷數(shù)據(jù)表,把相應的數(shù)據(jù)放到數(shù)組中即可
例如:
?php
//定義一個數(shù)組,用于保存讀取到的數(shù)據(jù)
$contents = array();
$query = mysql_query("select * from table");
//遍歷數(shù)據(jù)表
while($array = mysql_fetch_array($query)){
$contents[] = $array;
}
print_r($contents);
//然后循環(huán)數(shù)組,或者通過鍵名使用數(shù)組
foreach($contents as $value){
print_r($value);
}
echo $contents[0]['字段名稱'];
?
循環(huán)寫入示例如下(其他循環(huán)寫入原理也是一樣的):
?php
//定義空數(shù)組
$arr=?array();
//循環(huán)初始化條件
$i=1;
//根據(jù)判斷進行while循環(huán)
while($i=10){
//寫入數(shù)組
$arr[]="元素".$i;
//遞增
$i++;
}
print_r($arr);
/*
*?Array
(
[0]?=?元素1
[1]?=?元素2
[2]?=?元素3
[3]?=?元素4
[4]?=?元素5
[5]?=?元素6
[6]?=?元素7
[7]?=?元素8
[8]?=?元素9
[9]?=?元素10
)*/
?
本文名稱:php數(shù)據(jù)寫入數(shù)組中 php往數(shù)組中添加元素
網(wǎng)站路徑:http://muchs.cn/article24/dosjjce.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)頁設計公司、ChatGPT、微信小程序、品牌網(wǎng)站建設、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)