Beispiel #1
0
	public function falt_list () {
		 $page = isset($_REQUEST['page']) && intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;
		 $size = isset($_REQUEST['size']) && intval($_REQUEST['size'])  > 0 ? intval($_REQUEST['size'])  : 10;
		 $result = get_categories_tree();
		 if (!$result) {
	         $result = rpcLang('category.php', 'category_list_empty');
			 jsonExit("{\"status\":\"$result\"}");
		 }
		 //平铺
	     $flat_result = array();
	     arrayFlat($result, $flat_result);
	     $count = count($flat_result);
	     //获取分页信息
		 $pager  = get_pager('category.php',$_GET, $count, $page, $size);
		 $flat_result = array_slice($flat_result,$pager['start'],$size);
	     //print_r(array('flat_result'=>$flat_result, 'pager'=>$pager));exit;
	     jsonExit(array('flat_result'=>$flat_result, 'pager'=>$pager));
	}	
Beispiel #2
0
function arrayFlat($arr, &$result, $field = 'cat_id') {
    if (!is_array($arr)) return array();

    foreach ($arr as $one) {
        if (!is_array($one)) continue;
        $tem = $one;
        unset($tem[$field]);
        array_push($result, $tem);
        if (is_array($one[$field])) {
            arrayFlat($one[$field], $result, $field);
        }
    }
}