Home >Backend Development >PHP Tutorial >将相同数据合并显示的有关问题

将相同数据合并显示的有关问题

WBOY
WBOYOriginal
2016-06-13 10:20:37825browse

将相同数据合并显示的问题
我通过sql输出的数据格式如下
领导|张三
领导|李四
领导|王五
 想要的显示成表格形式:
领导|张三
  |李四
  |王五
请问如何实现

------解决方案--------------------

PHP code
$a=array(   array('领导','张三'),   array('领导','李四'),    array('领导','王五'));foreach($a as $k=>$b){       if(!$tem[$b[0]])             $tem[$b[0]]=$b;        else           $a[$k][0]='';   }echo "
";foreach($a as $v){ echo ""; echo ""; echo ""; echo "";}echo "
".$v[0]."|".$v[1]."
";
------解决方案--------------------
PHP code
header("content-type:text/html;charset=utf-8");$a=array(   array('领导','张三'),   array('领导','李四'),    array('领导','王五'));echo "
";foreach($a as $k => $v){ echo ""; if($k === 0) { echo ""; echo ""; } else { echo ""; } echo "";}echo "
".$v[0]."|".$v[1]." |".$v[1]."
";
Statement:
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