快乐每一天

自己选择的路,跪着也要走下去...

标签 二维数组 下的文章

PHP二维数组去重,最简单的方法

<?php
 
/*二维数组去掉重复值*/
 
$cc=array(
 '0' => 
  array (
    'wx_nickname' => '江淮智库',
    'wx_name' => 'anhui-sky',
    'url_times' => '0'
  ),
  '1' => 
  array (
    'wx_nickname' => '安徽发布',
    'wx_name' => 'anhuifabu',
    'url_times' => '0'
  ),
  '2' => 
  array (
    'wx_nickname' => '安徽发布',
    'wx_name' => 'anhuifabu',
    'url_times' => '0'
  )
);
 
 
$ee=[];
 
foreach ($cc as $k => $v) {
    if (!in_array($v['wx_nickname'],$ee)) {
        $ff[]=$v;
        $ee[]=$v['wx_nickname'];
    }
}
var_dump($ff);
?>
阅读全文

二维数组根据某个字段排序

<?php
 
$fuck=[['aa'=>'34','bb'=>'33'],['aa'=>'43','bb'=>'41'],['aa'=>'13','bb'=>'12'],['aa'=>'88','bb'=>'40']];
 
 
 
function array_sort($arr,$keys,$orderby='asc'){
  $keysvalue = $new_array = array();
  foreach ($arr as $k=>$v){
    $keysvalue[$k] = $v[$keys];
  }
  if($orderby== 'asc'){
    asort($keysvalue);
  }else{
    arsort($keysvalue);
  }
  reset($keysvalue);
  foreach ($keysvalue as $k=>$v){
    $new_array[] = $arr[$k];
  }
  return $new_array;
}
 
 
echo "<pre>";
print_r(array_sort($fuck,'aa','desc'));
echo "<pre>";
?>
阅读全文