請問如何將數組擴充

來源:互聯網
上載者:User
已經通過資料庫查詢得到一個數組,比如$data[0]['name']="張三",$data[1]['name']="李四",$data[0]['分數']=100,$data[0]['分數']=90,現在我想在數組中加一個欄位,比如【畢業院校】,而這個畢業院校不在資料庫中,在xml檔案中,我會寫一個函數function getyx('張三'),這樣就能得到院校了,這個我會,我想問的是怎樣把【畢業院校】這個欄位加到$data裡,使得我能通過$data[0]['畢業院校']這種方法得到對應的值。謝謝。

當然我知道不必非這樣,但是這裡主要是想弄會這個問題。謝謝。


回複討論(解決方案)

這樣嗎?

 '張三',        'score' => '100'    ),    array(        'name' => '李四',        'score' => '90'    ));$data[0]['school'] = 'school1';$data[1]['school'] = 'school2';echo '';print_r($data);?>


Array
(
[0] => Array
(
[name] => 張三
[score] => 100
[school] => school1
)

[1] => Array
(
[name] => 李四
[score] => 90
[school] => school2
)

)

既然是 通過資料庫查詢得到一個數組
那麼你在讀取查詢結果時就可加進去了

while($row = mysql_fetch_assoc($rs)) {  $row['畢業院校'] = getyx($row['name']);  $data[] = $row;}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.