我得到
警告:在第37行的/home/zeefashcp/public_html/catalog/model/bossthemes/boss_tagcloud.php中遇到的非数字值。
第37行"$spread = $max_qty - $min_qty;"
<?php
class ModelBossthemesBossTagCloud extends Model {
public function getRandomTags($limit = 5, $min_font_size = 9, $max_font_size = 25, $font_weight) {
$product_id = array();
$names = array();
$totals = array();
$tags = array();
$tagcloud = false;
$tagNameQuery = $this->db->query("SELECT DISTINCT tag FROM " . DB_PREFIX . "product_description WHERE language_id=" . (int)$this->config->get('config_language_id'));
if (count($tagNameQuery->rows) > 0) {
foreach ($tagNameQuery->rows as $row) {
if($row['tag']){
$names = explode(',', $row['tag']);
$totals = array_merge($totals, $names);
}
}
$tags = array_slice($totals, 0, $limit);
if($tags){
$tagcloud = $this->generateTagCloud($tags, true, $min_font_size, $max_font_size, $font_weight);
}
}
return $tagcloud;
}
private function generateTagCloud($tags, $resize = true, $min_font_size = 9, $max_font_size = 25, $font_weight) {
if ($resize == true) {
arsort($tags);
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));
$spread = $max_qty - $min_qty;
if ($spread == 0) { $spread = 1; }
$step = ((int)$max_font_size - (int)$min_font_size) / ($spread);
$cloud = array();
foreach ($tags as $key => $value) {
$size=rand((int)$min_font_size,(int)$max_font_size);
$cloud[] = '<a href="' . $this->url->link('product/search', 'tag=' . $value) . '" style="text-decoration:none;font-size:' . $size . 'px;font-weight:' . $font_weight . ';" title="">' . $value . '</a> ';
}
} else {
foreach ($tags as $key => $value) {
$cloud[] = '<a href="' . $this->url->link('product/search', 'tag=' . $value) . '" style="text-decoration:none;" title="">' . $value . '</a> ';
}
}
$tagcloud = '';
shuffle($cloud);
for ($x = 0; $x < count($cloud); $x++) {
$tagcloud .= $cloud[$x];
}
return $tagcloud;
}
}
?>
答案 0 :(得分:0)
您的$ tags数组仅包含字符串,可能至少包含一个非数字字符串,因此函数min()和max()不会返回整数,而是一个字符串。
这就是$spread = $max_qty - $min_qty;
不起作用的原因。
以下是PHP文档的摘录(功能min()):
将对多个非数字字符串值进行字母数字比较。返回的实际值将是原始类型,不应用任何转换。
由于我不知道您要尝试做什么,也不知道您的标签是什么样,所以我无法进一步帮助您。