请教怎么将数组扩展

WBOY
Release: 2016-06-13 12:13:32
Original
1096 people have browsed it

请问如何将数组扩展
已经通过数据库查询得到一个数组,比如$data[0]['name']="张三",$data[1]['name']="李四",$data[0]['分数']=100,$data[0]['分数']=90,现在我想在数组中加一个字段,比如【毕业院校】,而这个毕业院校不在数据库中,在xml文件中,我会写一个函数function getyx('张三'),这样就能得到院校了,这个我会,我想问的是怎样把【毕业院校】这个字段加到$data里,使得我能通过$data[0]['毕业院校']这种方法得到对应的值。谢谢。

当然我知道不必非这样,但是这里主要是想弄会这个问题。谢谢。
------解决思路----------------------
这样吗?

<br /><?php<br />$data = array(<br />    array(<br />        'name' => '张三',<br />        'score' => '100'<br />    ),<br />    array(<br />        'name' => '李四',<br />        'score' => '90'<br />    )<br />);<br /><br />$data[0]['school'] = 'school1';<br />$data[1]['school'] = 'school2';<br />echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';<br />print_r($data);<br /><br />?><br />
Copy after login


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

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

)
------解决思路----------------------
既然是 通过数据库查询得到一个数组
那么你在读取查询结果时就可加进去了
while($row = mysql_fetch_assoc($rs)) {<br />  $row['毕业院校'] = getyx($row['name']);<br />  $data[] = $row;<br />}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!