/** * 获取自定义banner信息 * @param id 菜单 * @return array(type,id) */ public function get_banner_info($id, $banner_confs) { $lists = array(); if (isset($banner_confs[$id])) { $lists = $banner_confs[$id]; } else { return $list; } $lists = sort_by_key($lists, 'rank'); foreach ($lists as &$list) { //如果有一些特定链接,在这边做转换 $list['link_org'] = $list['link']; $list['link'] = convert_link2json($list['link'], $list['type']); } return $lists; }
public function testSortByKey() { $array = [['type' => 'node', 'name' => 'html', 'childNodes' => []], ['type' => 'node', 'name' => 'body', 'childNodes' => []], ['type' => 'node', 'name' => 'h1', 'childNodes' => []]]; sort_by_key($array, 'name'); $this->assertEquals([['type' => 'node', 'name' => 'body', 'childNodes' => []], ['type' => 'node', 'name' => 'h1', 'childNodes' => []], ['type' => 'node', 'name' => 'html', 'childNodes' => []]], $array); }
/** * 获取banner基本信息 */ public static function get_banner_conf($menu_id) { $bigapp_page_alias = BigAppConf::$page_alias; $banner_conf = json_decode(get_option(BigAppConf::$option_banner_conf), true); $data['banner_list'] = array(); if (isset($banner_conf[$menu_id])) { $data['banner_list'] = sort_by_key($banner_conf[$menu_id], 'rank'); } $data['opt_url'] = admin_url("admin.php?page={$bigapp_page_alias}&action=menu"); //返回链接 return $data; }
function test_sort_by_key() { $data = array(); sort_by_key($data, 'id'); $this->assertTrue(array_compare($data, array())); $data = array(array('id' => 5, 'name' => 'snaf'), array('id' => 2, 'name' => 'bar'), array('id' => 1, 'name' => 'foo')); $expect = array(array('id' => 1, 'name' => 'foo'), array('id' => 2, 'name' => 'bar'), array('id' => 5, 'name' => 'snaf')); sort_by_key($data, 'id'); //print_r($actual); $this->assertTrue(array_compare($data, $expect)); $expect = array(array('id' => 2, 'name' => 'bar'), array('id' => 1, 'name' => 'foo'), array('id' => 5, 'name' => 'snaf')); sort_by_key($data, 'name'); //print_r($actual); $this->assertTrue(array_compare($data, $expect)); }
} } #重组数据 foreach ($items as $k => $item) { $tmp = explode('.', $item['name']); $file = DATA . "/" . $item['name']; $acc = unserialize(file_get_contents($file)); $acc = array_pop($acc); $item['wt'] = intval($acc['wt']); $item['pmu'] = intval($acc['pmu']); $item['viewurl'] = VIEWURL . "run=" . $tmp[0] . "&source=" . $tmp[1]; $items[$k] = $item; } #排序 if ($_GET['sort']) { sort_by_key($items, $_GET['sort']); } echo "<hr><center>"; echo "<div class='fv'>"; echo "<table width=1200>"; if ($p == 1) { $pp = ''; } else { $pp = $p; } echo "<tr><td>id</td><td>time</td><td width=80%><a href=?p={$pp}&sort=viewurl>url</a></td><td><a href=?p={$pp}&sort=wt>time cost(ms)</a></td><td><a href=?p={$pp}&sort=pmu>memory(byte)</a></td></tr>"; $id = 0; foreach ($items as $item) { echo "<tr><td>" . $id . "</td><td>" . date("Y-m-d H:i:s", $item['filetime']) . "</td><td><a href=\"" . $item['viewurl'] . "\" target=_blank>" . $item['name'] . "</a></td><td>" . number_format($item['wt']) . "</td><td>" . number_format($item['pmu']) . "</td></tr>"; $id++; if ($id > LIMIT) {