二維數組序號重置

public static function unique_arr($array2D,$stkeep=false,$ndformat=true){數組

// 判斷是否保留一級數組鍵 (一級數組鍵能夠爲非數字)orm

if($stkeep) $stArr = array_keys($array2D);字符串

// 判斷是否保留二級數組鍵 (全部二級數組鍵必須相同)io

if($ndformat) $ndArr = array_keys(end($array2D));function

//降維,也能夠用implode,將一維數組轉換爲用逗號鏈接的字符串form

foreach ($array2D as $v){dva

$v = join(",",$v);foreach

$temp[] = $v;im

}static

//去掉重複的字符串,也就是重複的一維數組

$temp = array_unique($temp);

//再將拆開的數組從新組裝

foreach ($temp as $k => $v)

{

if($stkeep) $k = $stArr[$k];

if($ndformat)

{

$tempArr = explode(",",$v);

foreach($tempArr as $ndkey => $ndval) $output[$k][$ndArr[$ndkey]] = $ndval;

}

else $output[$k] = explode(",",$v);

}

return $output;

}

相關文章
相關標籤/搜索