php二维数组的问题,求大神解答
我现在有个页面searchFangxiang.php定义了一个二维数组:
$fangxiang=array('fid101'=>array("fid"=>"101","Name"=>"自动化研究所","professor"=>"张教授"),
'fid102'=>array("fid"=>"102","Name"=>"实验室","professor"=>"李教授"),
'fid103'=>array("fid"=>"103","Name"=>"科学研究所","professor"=>"王教授")););
?>
然后在我的应用页面引用了这个二维数组的页面
<br /><?php<br />$fangxiang = array(<br /> 'fid101' => array("fid"=>"101","Name"=>"自动化研究所","professor"=>"张教授"),<br /> 'fid102' => array("fid"=>"102","Name"=>"实验室","professor"=>"李教授"),<br /> 'fid103' => array("fid"=>"103","Name"=>"科学研究所","professor"=>"王教授"),<br />);<br />?><br /><meta http-equiv="content-type" content="text/html; charset=utf-8"><br /><script type="text/javascript"><br />var fangxiang = <?php echo json_encode($fangxiang); ?>;<br /><br />function search(){<br /> var key = document.getElementById("key").value;<br /> var type = document.getElementById("type").value;<br /><br /> if(key==''){<br /> alert('请输入要搜寻的关键字');<br /> return false;<br /> }<br /><br /> var result = [];<br /><br /> for(var row in fangxiang){<br /> var tmp = fangxiang[row][type];<br /> if(tmp.indexOf(key)!=-1){<br /> result.push(row);<br /> }<br /> }<br /><br /> var response = '';<br /><br /> if(result.length>0){<br /> for(var i=0,len=result.length; i<len; i++){<br /> response += fangxiang[result[i]].fid + ' ' + fangxiang[result[i]].Name + ' ' + fangxiang[result[i]].professor + ' <br>';<br /> }<br /> }<br /><br /> document.getElementById('result').innerHTML = response;<br />}<br /></script><br /><br /><p>search key:<input type="text" id="key"></p><br /><p>type:<select id="type"><br /> <option value="Name">Name</option><br /> <option value="professor">professor</option><br /></select><br /></p><br /><p><input type="button" value="search" onclick="search()"></p><br /><div id="result"></div><br />