/** * 返回当前运行文件名 * @acces private * @return string */ private function run_filename() { $tmparr = explode(DIRECTORY_SEPARATOR,__FILE__); return end($tmparr); } //例: $this->run_filename();//返回当前文件名
/** * 递归一维重复数组值 * @以键名为数量值 * @acces private * @return array */ private function recursion_arr($arr,$data=[]) { $unique_arr = array_unique ( $arr ); $repeat_arr = array_diff_assoc ( $arr, $unique_arr ); foreach(array_unique($repeat_arr) as $repeat_arr_val) { $repeat_arr_key = array_search($repeat_arr_val,$unique_arr); unset($unique_arr[$repeat_arr_key]); } $start_count = count($repeat_arr); $tmp = array_unique($repeat_arr); $executed_count = count($tmp); $data[] = $unique_arr; if($start_count > $executed_count) { //如果有相同的值,继续回调 $result = $this->recursion_arr($repeat_arr,$data); return $result; //一层一层传上来 }else{ if($repeat_arr) { $data[] = $repeat_arr; } return $data; //直到底层开始返回结果 } }
//例: $arr = array( 0=>1, 1=>2, 2=>2, 3=>3, 4=>3, 5=>3, 6=>4, 7=>4, 8=>4, 9=>4, ); $this->recursion_arr($arr); //结果: array( 0=>array( 0=>1 ), 1=>array( 0=>2, 1=>2 ), 2=>array( 0=>3, 1=>3, 2=>3 ), 3=>array( 0=>4, 1=>4, 2=>4, 3=>4 ) );