标签:
<?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { //原始数据 /*Array ( [0] => Array ( [ap] => 23 [ac] => 569418 ) [1] => Array ( [ap] => 23 [ac] => 569520 ) [2] => Array ( [ap] => 23 [ac] => 569533 ) )*/ //除去重复值后的数据 /*Array ( [23] => Array ( [ap] => 23 [ac] => 569418 ) )*/ public function index(){ $arr=array(); $arr=array(‘0‘=>array(‘ap‘=>‘23‘,‘ac‘=>‘569418‘), ‘1‘=>array(‘ap‘=>‘23‘,‘ac‘=>‘569520‘),‘2‘=>array(‘ap‘=>‘23‘,‘ac‘=>‘569533‘)); print_r($arr); $key=‘ap‘; $arr=$this->array_unset($arr,$key); print_r($arr); //$this->display(); } //二维数组去除特定键的重复项 public function array_unset($arr,$key){//$arr->传入数组 $key->判断的key值 //建立一个目标数组 $res = array(); foreach (array_reverse($arr) as $value){//array_reverse() php 数组顺序反转 if(isset($res[$value[$key]])){//查看有没有重复项 unset($value[$key]);//有:销毁 }else{ $res[$value[$key]] = $value; } } return $res; } } ?>
标签:
原文地址:http://www.cnblogs.com/719907411hl/p/4963063.html