Home >Backend Development >PHP Tutorial >数组有关问题,标题要长。

数组有关问题,标题要长。

WBOY
WBOYOriginal
2016-06-13 10:26:03868browse

请教大家数组问题,标题要长。。。

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$arr=array(                        array('name' => 'aa','id' => '456'),                        array('name' => 'bb','id' => '25',),                        array('name' => 'cc','id' => '25',),                        array('name' => 'dd','id' => '456',),                    );

怎么取出ID相同的name.提示出来。比如这个数组提示 aa 和 dd的id相同 ,bb 和 cc 的id相同

------解决方案--------------------
自己搞定了~!~

PHP code
                                $newArr=array();                                foreach($deals_info as $key=>$value){                                    if(!isset($newArr[$value['id']])){                                           $newArr[$value['id']][]=$value['name'];                                    }else{                                        foreach($newArr as $k=>$v){                                            if($k==$value['id'] and !in_array($value['name'],$newArr[$k])){                                                    $newArr[$k][]=$value['name'];                                            }                                        }                                    }                                }<div class="clear">
                 
              
              
        
            </div>
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