日期:2014-05-17 浏览次数:20594 次
$a = array( array('2120844', 'DJ小罗Remix这该死的温柔DISCO'), array('2120843', 'lucky_twice-魔法项链第一首-DJ-舞曲-慢摇'), array('2120842', 'Beautiful_Girls_(DJ→梦←Extended_Remix)'), array('2120841', 'DjRuico_FunkyHouse_Remix'), ); $b = array( array('OKNDR1', 'DjRuico_FunkyHouse_Remix'), array('DGERR2', 'lucky_twice-魔法项链第一首-DJ-舞曲-慢摇'), array('EGDSF3', 'DJ小罗Remix这该死的温柔DISCO'), array('EEEED4', 'Beautiful_Girls_(DJ→梦←Extended_Remix)'), ); $r = array(); foreach($a as $v) $r[$v[1]][] = $v[0]; foreach($b as $v) $r[$v[1]][] = $v[0]; foreach($r as $k=>$v) echo "$k [a]$v[0][/a] [bb]$v[1][/bb]\n";
------解决方案--------------------
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>test</title> <style> td{ padding:20px; } </style> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="right"> <textarea name="textarea" id="text1" cols="60" rows="6"></textarea></td> <td align="center"><input type="button" name="button" id="button" value="转换" style="width:100px; height:100px" onClick="text3()"></td> <td><textarea name="textarea2" id="text2" cols="60" rows="6"></textarea></td> </tr> <tr> <td colspan="3" align="center"><textarea name="textarea3" id="text3" cols="80" rows="6"></textarea></td> </tr> </table> </body> </html> <script> function $(id){ return document.getElementById(id); } function text3(){ var text1=$('text1').value; var textArray1=text1.split('\n'); var text2=$('text2').value; var textArray2=text2.split('\n'); var colArray1,colArray2; var resultStr=''; for(var i1 in textArray1){ colArray1=textArray1[i1].split(' '); for(var i2 in textArray2){ colArray2=textArray2[i2].split(' '); if(colArray1[1]==colArray2[1]){ resultStr+=colArray1[1]+' [a]'+colArray1[0]+'[/a] [bb]'+colArray2[0]+'[/bb]\n'; } } } $('text3').value=resultStr; } </script>