function widget_tag($title) { global $CACHE; $tag_cache = $CACHE->readCache('tags'); $tag_cache = array_multi_sort($tag_cache, 'usenum'); ?> <div class="widget widget_tag"> <h3><?php echo $title; ?> </h3> <div class="J_tags"> <?php if (!$tag_cache) { echo '暂无关键词'; } ?> <?php $count = 0; foreach ($tag_cache as $value) { ?> <?php if ($count >= 40) { break; } ?> <a href="<?php echo Url::tag($value['tagurl']); ?> " title="<?php echo $value['tagname']; ?> " rel="nofollow"><?php echo $value['tagname']; ?> (<?php echo $value['usenum']; ?> )</a> <?php $count++; ?> <?php } ?> </div> </div> <?php }
function widget_tag($title) { global $CACHE; $tag_cache = $CACHE->readCache('tags'); $tag_cache = array_multi_sort($tag_cache, 'usenum'); if (is_array($tag_cache)) { $tag_cache = array_merge($tag_cache); #强制索引从0递增 } $delly_spider = !_g('allow_tags_spider'); $is_all = _g('max_tags'); $max_tags = !$is_all ? PHP_INT_MAX : $is_all; #php5.0.5之后的常量 php版本限制!!!!! ?> <div class="widget widget_tag"> <h3><?php echo $title; ?> </h3> <div class="J_tags"> <?php if (!$tag_cache) { echo '暂无关键词'; } ?> <?php $num = 0; foreach ($tag_cache as $value) { ?> <?php if ($num >= $max_tags) { break; } ?> <a href="<?php echo Url::tag($value['tagurl']); ?> " title="<?php echo $value['tagname']; ?> " <?php if ($delly_spider) { echo ' rel="nofollow"'; } ?> ><?php echo $value['tagname']; ?> (<?php echo $value['usenum']; ?> )</a> <?php $num++; ?> <?php } ?> </div> </div> <?php }
} // demo of complex array sorting $demoarray = array('whatever' => array('first' => 25, 'second' => 'fred'), 'whatever2' => array('first' => 36, 'second' => 'simone'), 'whatever3' => array('first' => 12, 'second' => 'tom'), 'whatever4' => array('first' => 3, 'second' => 'peter'), 'whatever5' => array('first' => 56, 'second' => 'maria')); $sortorder = 'desc'; $index = 'first'; $demoarray = array_multi_sort($demoarray, $index, $sortorder); echo ' <p> array sorted by fieldname "' . $index . '" in ' . $sortorder . 'ending order </p> <p>'; foreach ($demoarray as $row) { echo ' ' . print_r($row["first"] . $row["second"], true) . '<br />'; } echo ' </p>'; $sortorder = 'asc'; $index = 'second'; $demoarray = array_multi_sort($demoarray, $index, $sortorder); echo ' <p> array sorted by fieldname "' . $index . '" in ' . $sortorder . 'ending order </p> <p>'; foreach ($demoarray as $row) { echo ' ' . print_r($row["first"] . $row["second"], true) . '<br />'; } echo ' </p>';