PHP 警告:number_format() 期望参数 1 为浮点数
Posted
技术标签:
【中文标题】PHP 警告:number_format() 期望参数 1 为浮点数【英文标题】:PHP Warning: number_format() expects parameter 1 to be float 【发布时间】:2018-09-29 21:11:07 【问题描述】:请有人帮我解决我得到的这段代码
,字符串在第 39 行给出
我是全班抄的,希望能帮助你更好地找到问题。
class stats_site extends stats
function __construct()
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['stats_header'];
$TMPL['username'] = $DB->escape($FORM['u'], 1);
$stats = $DB->fetch("SELECT * FROM $CONF['sql_prefix']_stats WHERE username = '$TMPL['username']'", __FILE__, __LINE__);
unset($stats['username']);
$sites = array($DB->fetch("SELECT * FROM $CONF['sql_prefix']_sites WHERE username = '$TMPL['username']'", __FILE__, __LINE__));
if ($stats)
$TMPL = array_merge($TMPL, $stats, $sites);
$TMPL['unq_pv_max_daily'] = $TMPL['unq_pv_0_daily'] > $TMPL['unq_pv_max_daily'] ? $TMPL['unq_pv_0_daily'] : $TMPL['unq_pv_max_daily'];
$TMPL['tot_pv_max_daily'] = $TMPL['tot_pv_0_daily'] > $TMPL['tot_pv_max_daily'] ? $TMPL['tot_pv_0_daily'] : $TMPL['tot_pv_max_daily'];
$TMPL['unq_in_max_daily'] = $TMPL['unq_in_0_daily'] > $TMPL['unq_in_max_daily'] ? $TMPL['unq_in_0_daily'] : $TMPL['unq_in_max_daily'];
$TMPL['tot_in_max_daily'] = $TMPL['tot_in_0_daily'] > $TMPL['tot_in_max_daily'] ? $TMPL['tot_in_0_daily'] : $TMPL['tot_in_max_daily'];
$TMPL['unq_out_max_daily'] = $TMPL['unq_out_0_daily'] > $TMPL['unq_out_max_daily'] ? $TMPL['unq_out_0_daily'] : $TMPL['unq_out_max_daily'];
$TMPL['tot_out_max_daily'] = $TMPL['tot_out_0_daily'] > $TMPL['tot_out_max_daily'] ? $TMPL['tot_out_0_daily'] : $TMPL['tot_out_max_daily'];
$TMPL['unq_pv_max_weekly'] = $TMPL['unq_pv_0_weekly'] > $TMPL['unq_pv_max_weekly'] ? $TMPL['unq_pv_0_weekly'] : $TMPL['unq_pv_max_weekly'];
$TMPL['tot_pv_max_weekly'] = $TMPL['tot_pv_0_weekly'] > $TMPL['tot_pv_max_weekly'] ? $TMPL['tot_pv_0_weekly'] : $TMPL['tot_pv_max_weekly'];
$TMPL['unq_in_max_weekly'] = $TMPL['unq_in_0_weekly'] > $TMPL['unq_in_max_weekly'] ? $TMPL['unq_in_0_weekly'] : $TMPL['unq_in_max_weekly'];
$TMPL['tot_in_max_weekly'] = $TMPL['tot_in_0_weekly'] > $TMPL['tot_in_max_weekly'] ? $TMPL['tot_in_0_weekly'] : $TMPL['tot_in_max_weekly'];
$TMPL['unq_out_max_weekly'] = $TMPL['unq_out_0_weekly'] > $TMPL['unq_out_max_weekly'] ? $TMPL['unq_out_0_weekly'] : $TMPL['unq_out_max_weekly'];
$TMPL['tot_out_max_weekly'] = $TMPL['tot_out_0_weekly'] > $TMPL['tot_out_max_weekly'] ? $TMPL['tot_out_0_weekly'] : $TMPL['tot_out_max_weekly'];
$TMPL['unq_pv_max_monthly'] = $TMPL['unq_pv_0_monthly'] > $TMPL['unq_pv_max_monthly'] ? $TMPL['unq_pv_0_monthly'] : $TMPL['unq_pv_max_monthly'];
$TMPL['tot_pv_max_monthly'] = $TMPL['tot_pv_0_monthly'] > $TMPL['tot_pv_max_monthly'] ? $TMPL['tot_pv_0_monthly'] : $TMPL['tot_pv_max_monthly'];
$TMPL['unq_in_max_monthly'] = $TMPL['unq_in_0_monthly'] > $TMPL['unq_in_max_monthly'] ? $TMPL['unq_in_0_monthly'] : $TMPL['unq_in_max_monthly'];
$TMPL['tot_in_max_monthly'] = $TMPL['tot_in_0_monthly'] > $TMPL['tot_in_max_monthly'] ? $TMPL['tot_in_0_monthly'] : $TMPL['tot_in_max_monthly'];
$TMPL['unq_out_max_monthly'] = $TMPL['unq_out_0_monthly'] > $TMPL['unq_out_max_monthly'] ? $TMPL['unq_out_0_monthly'] : $TMPL['unq_out_max_monthly'];
$TMPL['tot_out_max_monthly'] = $TMPL['tot_out_0_monthly'] > $TMPL['tot_out_max_monthly'] ? $TMPL['tot_out_0_monthly'] : $TMPL['tot_out_max_monthly'];
$this->averages();
$TMPL['average_rating'] = $TMPL['num_ratings'] > 0 ? round($TMPL['total_rating'] / $TMPL['num_ratings'], 0) : 0;
$stats = array_map('number_format', $stats);
$TMPL = array_merge($TMPL, $stats);
$this->locale();
$TMPL['header'] .= " - $TMPL['title']";
$TMPL['category_url'] = urlencode($TMPL['category']);
$query = "SELECT id, date, review FROM $CONF['sql_prefix']_reviews WHERE username = '$TMPL['username']' AND active = 1";
if (isset($FORM['all_reviews']) && $FORM['all_reviews'])
$result = $DB->query("$query ORDER BY date DESC", __FILE__, __LINE__);
else
$result = $DB->select_limit("$query ORDER BY RAND()", 2, 0, __FILE__, __LINE__);
$TMPL['reviews'] = '';
while (list($TMPL['id'], $TMPL['date'], $TMPL['review']) = $DB->fetch_array($result))
$TMPL['reviews'] .= $this->do_skin('stats_review');
$TMPL['content'] = $this->do_skin('stats');
else
$this->error($LNG['g_invalid_u']);
第 39 行是这里的这一行:
$stats = array_map('number_format', $stats);
提前非常感谢!
编辑
我已将完整代码放在这里,以便您更好地解决问题。 我在这里尝试了您的所有建议,但没有帮助:(
这里是完整的代码:
<?php
if (!defined('ATSPHP'))
die("This file cannot be accessed directly.");
class stats extends base
function __construct()
global $FORM;
if (isset($FORM['u'])) $stats = new stats_site;
else $stats = new stats_overall;
function averages()
global $TMPL;
$ranking_periods = array('daily', 'weekly', 'monthly');
$ranking_methods = array('unq_pv', 'tot_pv', 'unq_in', 'tot_in', 'unq_out', 'tot_out');
foreach ($ranking_periods as $ranking_period)
foreach ($ranking_methods as $ranking_method)
$TMPL["$ranking_method_avg_$ranking_period"] = 0;
for ($i = 0; $i < 10; $i++)
$TMPL["$ranking_method_avg_$ranking_period"] = $TMPL["$ranking_method_avg_$ranking_period"] + $TMPL["$ranking_method_$i_$ranking_period"];
$TMPL["$ranking_method_avg_$ranking_period"] = number_format($TMPL["$ranking_method_avg_$ranking_period"] / 10, 1);
function locale()
global $CONF, $LNG, $TMPL;
setlocale(LC_ALL, $CONF['default_language']);
for ($i = 2; $i < 10; $i++)
$TMPL["$i_daily"] = strftime('%B %d', time()-3600*24*$i + (3600*$CONF['time_offset']));
for ($i = 2; $i < 10; $i++)
$TMPL["$i_weekly"] = "$LNG['stats_week'] ".date('W', time()-3600*24*7*$i + (3600*$CONF['time_offset']));
for ($i = 2; $i < 10; $i++)
$TMPL["$i_monthly"] = strftime('%B %y', mktime(0, 0, 0, date('m')-$i, 1));
class stats_site extends stats
function __construct()
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['stats_header'];
$TMPL['username'] = $DB->escape($FORM['u'], 1);
$stats = $DB->fetch("SELECT * FROM $CONF['sql_prefix']_stats WHERE username = '$TMPL['username']'", __FILE__, __LINE__);
unset($stats['username']);
$sites = array($DB->fetch("SELECT * FROM $CONF['sql_prefix']_sites WHERE username = '$TMPL['username']'", __FILE__, __LINE__));
if ($stats)
$TMPL = array_merge($TMPL, $stats, $sites);
$TMPL['unq_pv_max_daily'] = $TMPL['unq_pv_0_daily'] > $TMPL['unq_pv_max_daily'] ? $TMPL['unq_pv_0_daily'] : $TMPL['unq_pv_max_daily'];
$TMPL['tot_pv_max_daily'] = $TMPL['tot_pv_0_daily'] > $TMPL['tot_pv_max_daily'] ? $TMPL['tot_pv_0_daily'] : $TMPL['tot_pv_max_daily'];
$TMPL['unq_in_max_daily'] = $TMPL['unq_in_0_daily'] > $TMPL['unq_in_max_daily'] ? $TMPL['unq_in_0_daily'] : $TMPL['unq_in_max_daily'];
$TMPL['tot_in_max_daily'] = $TMPL['tot_in_0_daily'] > $TMPL['tot_in_max_daily'] ? $TMPL['tot_in_0_daily'] : $TMPL['tot_in_max_daily'];
$TMPL['unq_out_max_daily'] = $TMPL['unq_out_0_daily'] > $TMPL['unq_out_max_daily'] ? $TMPL['unq_out_0_daily'] : $TMPL['unq_out_max_daily'];
$TMPL['tot_out_max_daily'] = $TMPL['tot_out_0_daily'] > $TMPL['tot_out_max_daily'] ? $TMPL['tot_out_0_daily'] : $TMPL['tot_out_max_daily'];
$TMPL['unq_pv_max_weekly'] = $TMPL['unq_pv_0_weekly'] > $TMPL['unq_pv_max_weekly'] ? $TMPL['unq_pv_0_weekly'] : $TMPL['unq_pv_max_weekly'];
$TMPL['tot_pv_max_weekly'] = $TMPL['tot_pv_0_weekly'] > $TMPL['tot_pv_max_weekly'] ? $TMPL['tot_pv_0_weekly'] : $TMPL['tot_pv_max_weekly'];
$TMPL['unq_in_max_weekly'] = $TMPL['unq_in_0_weekly'] > $TMPL['unq_in_max_weekly'] ? $TMPL['unq_in_0_weekly'] : $TMPL['unq_in_max_weekly'];
$TMPL['tot_in_max_weekly'] = $TMPL['tot_in_0_weekly'] > $TMPL['tot_in_max_weekly'] ? $TMPL['tot_in_0_weekly'] : $TMPL['tot_in_max_weekly'];
$TMPL['unq_out_max_weekly'] = $TMPL['unq_out_0_weekly'] > $TMPL['unq_out_max_weekly'] ? $TMPL['unq_out_0_weekly'] : $TMPL['unq_out_max_weekly'];
$TMPL['tot_out_max_weekly'] = $TMPL['tot_out_0_weekly'] > $TMPL['tot_out_max_weekly'] ? $TMPL['tot_out_0_weekly'] : $TMPL['tot_out_max_weekly'];
$TMPL['unq_pv_max_monthly'] = $TMPL['unq_pv_0_monthly'] > $TMPL['unq_pv_max_monthly'] ? $TMPL['unq_pv_0_monthly'] : $TMPL['unq_pv_max_monthly'];
$TMPL['tot_pv_max_monthly'] = $TMPL['tot_pv_0_monthly'] > $TMPL['tot_pv_max_monthly'] ? $TMPL['tot_pv_0_monthly'] : $TMPL['tot_pv_max_monthly'];
$TMPL['unq_in_max_monthly'] = $TMPL['unq_in_0_monthly'] > $TMPL['unq_in_max_monthly'] ? $TMPL['unq_in_0_monthly'] : $TMPL['unq_in_max_monthly'];
$TMPL['tot_in_max_monthly'] = $TMPL['tot_in_0_monthly'] > $TMPL['tot_in_max_monthly'] ? $TMPL['tot_in_0_monthly'] : $TMPL['tot_in_max_monthly'];
$TMPL['unq_out_max_monthly'] = $TMPL['unq_out_0_monthly'] > $TMPL['unq_out_max_monthly'] ? $TMPL['unq_out_0_monthly'] : $TMPL['unq_out_max_monthly'];
$TMPL['tot_out_max_monthly'] = $TMPL['tot_out_0_monthly'] > $TMPL['tot_out_max_monthly'] ? $TMPL['tot_out_0_monthly'] : $TMPL['tot_out_max_monthly'];
$this->averages();
$TMPL['average_rating'] = $TMPL['num_ratings'] > 0 ? round($TMPL['total_rating'] / $TMPL['num_ratings'], 0) : 0;
function formatter($stats) return number_format(floatval($stats));
$stats = array_map('number_format', $stats);
//$stats = array_map(function($v)return is_numeric($v) ? number_format($v) : $v;, $stats);
$TMPL = array_merge($TMPL, $stats);
$this->locale();
$TMPL['header'] .= " - $TMPL['title']";
$TMPL['category_url'] = urlencode($TMPL['category']);
$query = "SELECT id, date, review FROM $CONF['sql_prefix']_reviews WHERE username = '$TMPL['username']' AND active = 1";
if (isset($FORM['all_reviews']) && $FORM['all_reviews'])
$result = $DB->query("$query ORDER BY date DESC", __FILE__, __LINE__);
else
$result = $DB->select_limit("$query ORDER BY RAND()", 2, 0, __FILE__, __LINE__);
$TMPL['reviews'] = '';
while (list($TMPL['id'], $TMPL['date'], $TMPL['review']) = $DB->fetch_array($result))
$TMPL['reviews'] .= $this->do_skin('stats_review');
$TMPL['content'] = $this->do_skin('stats');
else
$this->error($LNG['g_invalid_u']);
class stats_overall extends stats
function __construct()
global $CONF, $DB, $FORM, $LNG, $TMPL;
$TMPL['header'] = $LNG['stats_overall'];
$stats = $DB->fetch("SELECT SUM(unq_pv_overall), SUM(tot_pv_overall), SUM(unq_in_overall), SUM(tot_in_overall), SUM(unq_out_overall), SUM(tot_out_overall),
SUM(unq_pv_0_daily), SUM(unq_pv_1_daily), SUM(unq_pv_2_daily), SUM(unq_pv_3_daily), SUM(unq_pv_4_daily), SUM(unq_pv_5_daily), SUM(unq_pv_6_daily), SUM(unq_pv_7_daily), SUM(unq_pv_8_daily), SUM(unq_pv_9_daily), SUM(tot_pv_0_daily), SUM(tot_pv_1_daily), SUM(tot_pv_2_daily), SUM(tot_pv_3_daily), SUM(tot_pv_4_daily), SUM(tot_pv_5_daily), SUM(tot_pv_6_daily), SUM(tot_pv_7_daily), SUM(tot_pv_8_daily), SUM(tot_pv_9_daily),
SUM(unq_in_0_daily), SUM(unq_in_1_daily), SUM(unq_in_2_daily), SUM(unq_in_3_daily), SUM(unq_in_4_daily), SUM(unq_in_5_daily), SUM(unq_in_6_daily), SUM(unq_in_7_daily), SUM(unq_in_8_daily), SUM(unq_in_9_daily), SUM(tot_in_0_daily), SUM(tot_in_1_daily), SUM(tot_in_2_daily), SUM(tot_in_3_daily), SUM(tot_in_4_daily), SUM(tot_in_5_daily), SUM(tot_in_6_daily), SUM(tot_in_7_daily), SUM(tot_in_8_daily), SUM(tot_in_9_daily),
SUM(unq_out_0_daily), SUM(unq_out_1_daily), SUM(unq_out_2_daily), SUM(unq_out_3_daily), SUM(unq_out_4_daily), SUM(unq_out_5_daily), SUM(unq_out_6_daily), SUM(unq_out_7_daily), SUM(unq_out_8_daily), SUM(unq_out_9_daily), SUM(tot_out_0_daily), SUM(tot_out_1_daily), SUM(tot_out_2_daily), SUM(tot_out_3_daily), SUM(tot_out_4_daily), SUM(tot_out_5_daily), SUM(tot_out_6_daily), SUM(tot_out_7_daily), SUM(tot_out_8_daily), SUM(tot_out_9_daily),
SUM(unq_pv_0_weekly), SUM(unq_pv_1_weekly), SUM(unq_pv_2_weekly), SUM(unq_pv_3_weekly), SUM(unq_pv_4_weekly), SUM(unq_pv_5_weekly), SUM(unq_pv_6_weekly), SUM(unq_pv_7_weekly), SUM(unq_pv_8_weekly), SUM(unq_pv_9_weekly), SUM(tot_pv_0_weekly), SUM(tot_pv_1_weekly), SUM(tot_pv_2_weekly), SUM(tot_pv_3_weekly), SUM(tot_pv_4_weekly), SUM(tot_pv_5_weekly), SUM(tot_pv_6_weekly), SUM(tot_pv_7_weekly), SUM(tot_pv_8_weekly), SUM(tot_pv_9_weekly),
SUM(unq_in_0_weekly), SUM(unq_in_1_weekly), SUM(unq_in_2_weekly), SUM(unq_in_3_weekly), SUM(unq_in_4_weekly), SUM(unq_in_5_weekly), SUM(unq_in_6_weekly), SUM(unq_in_7_weekly), SUM(unq_in_8_weekly), SUM(unq_in_9_weekly), SUM(tot_in_0_weekly), SUM(tot_in_1_weekly), SUM(tot_in_2_weekly), SUM(tot_in_3_weekly), SUM(tot_in_4_weekly), SUM(tot_in_5_weekly), SUM(tot_in_6_weekly), SUM(tot_in_7_weekly), SUM(tot_in_8_weekly), SUM(tot_in_9_weekly),
SUM(unq_out_0_weekly), SUM(unq_out_1_weekly), SUM(unq_out_2_weekly), SUM(unq_out_3_weekly), SUM(unq_out_4_weekly), SUM(unq_out_5_weekly), SUM(unq_out_6_weekly), SUM(unq_out_7_weekly), SUM(unq_out_8_weekly), SUM(unq_out_9_weekly), SUM(tot_out_0_weekly), SUM(tot_out_1_weekly), SUM(tot_out_2_weekly), SUM(tot_out_3_weekly), SUM(tot_out_4_weekly), SUM(tot_out_5_weekly), SUM(tot_out_6_weekly), SUM(tot_out_7_weekly), SUM(tot_out_8_weekly), SUM(tot_out_9_weekly),
SUM(unq_pv_0_monthly), SUM(unq_pv_1_monthly), SUM(unq_pv_2_monthly), SUM(unq_pv_3_monthly), SUM(unq_pv_4_monthly), SUM(unq_pv_5_monthly), SUM(unq_pv_6_monthly), SUM(unq_pv_7_monthly), SUM(unq_pv_8_monthly), SUM(unq_pv_9_monthly), SUM(tot_pv_0_monthly), SUM(tot_pv_1_monthly), SUM(tot_pv_2_monthly), SUM(tot_pv_3_monthly), SUM(tot_pv_4_monthly), SUM(tot_pv_5_monthly), SUM(tot_pv_6_monthly), SUM(tot_pv_7_monthly), SUM(tot_pv_8_monthly), SUM(tot_pv_9_monthly),
SUM(unq_in_0_monthly), SUM(unq_in_1_monthly), SUM(unq_in_2_monthly), SUM(unq_in_3_monthly), SUM(unq_in_4_monthly), SUM(unq_in_5_monthly), SUM(unq_in_6_monthly), SUM(unq_in_7_monthly), SUM(unq_in_8_monthly), SUM(unq_in_9_monthly), SUM(tot_in_0_monthly), SUM(tot_in_1_monthly), SUM(tot_in_2_monthly), SUM(tot_in_3_monthly), SUM(tot_in_4_monthly), SUM(tot_in_5_monthly), SUM(tot_in_6_monthly), SUM(tot_in_7_monthly), SUM(tot_in_8_monthly), SUM(tot_in_9_monthly),
SUM(unq_out_0_monthly), SUM(unq_out_1_monthly), SUM(unq_out_2_monthly), SUM(unq_out_3_monthly), SUM(unq_out_4_monthly), SUM(unq_out_5_monthly), SUM(unq_out_6_monthly), SUM(unq_out_7_monthly), SUM(unq_out_8_monthly), SUM(unq_out_9_monthly), SUM(tot_out_0_monthly), SUM(tot_out_1_monthly), SUM(tot_out_2_monthly), SUM(tot_out_3_monthly), SUM(tot_out_4_monthly), SUM(tot_out_5_monthly), SUM(tot_out_6_monthly), SUM(tot_out_7_monthly), SUM(tot_out_8_monthly), SUM(tot_out_9_monthly)
FROM $CONF['sql_prefix']_stats", __FILE__, __LINE__);
// Get rid of SUM() in array keys
foreach ($stats as $key => $value)
$new_key = str_replace(array('SUM(', ')'), '', $key);
$stats[$new_key] = $value;
unset($stats[$key]);
$TMPL = array_merge($TMPL, $stats);
$this->averages();
$stats = array_map('number_format', $stats);
$TMPL = array_merge($TMPL, $stats);
$this->locale();
$TMPL['content'] = $this->do_skin('stats_overall');
?>
错误发生在第 85 行:
$stats = array_map('number_format', $stats);
使用 Miken32 的答案后的最新错误:
PHP 通知:未定义索引:sources/stats.php 第 91 行中的标题 PHP 通知:未定义索引:sources/stats.php 第 92 行中的类别 PHP 注意:未定义索引:sources/misc/skin.php(84) 中的标题:第 1 行运行时创建的函数 PHP 注意:未定义索引:sources/misc/ 等中的 url。
【问题讨论】:
$stats
中有什么内容?该数组中至少有一个元素不是数字。
@miken32 我现在放了完整的 PHP 代码,你现在可以帮我吗?您提供的所有变体都没有帮助!非常感谢!
我两天前发布了一个答案。
@miken32 我试过了,但没有解决我的问题,你现在有完整的页面代码,我在上面编辑了我的帖子。
@Farer 如果您尝试过 Miken32 的回答;该错误将与您在第 85 行所述的错误不同;使用 Miken32 的代码给您带来的不同错误是什么?或者以其他方式澄清 HOW 它不起作用
【参考方案1】:
array_map()
将函数应用于数组的每个元素。在这种情况下,您将向它传递一个函数的名称(“number_format”),该函数需要一个数字,但它正在获取一个字符串。相反,您可以将自己的函数传递给它来检查它:
$stats = array_map(function($v)return is_numeric($v) ? number_format($v) : $v;, $stats);
【讨论】:
我试过这个,但它没有帮助我,你可以在完整的代码中看到我在尝试时注释掉了该行并且认识到它并没有解决我的问题。还是谢谢! @Farer 如果您尝试过 Miken32 的回答;该错误将与您在第 85 行所述的错误不同;使用 Miken32 的代码给您带来的不同错误是什么?或者以其他方式澄清它是如何不起作用的 @Martin 是的,现在错误不同了,我现在得到了这个错误: @Farer 好吧.....然后不要对 Miken32 说“它不起作用”,编辑您的问题并在底部添加 new 出现上面给出的答案的错误消息。谢谢。 @Martin 未定义索引:第 91 行的标题 未定义的索引:第 92 行的类别 未定义的索引:第 1 行的标题运行时创建的函数 未定义的索引:第 1 行的 url 运行时创建的函数 PHP 注意:未定义索引:banner_url 第 1 行运行时创建的函数未定义索引:标题第 1 行未定时创建的函数 // 等等...【参考方案2】:默认情况下,来自 mysql 的数字类型在 php.ini 中作为字符串值返回。最简单的做法是创建一个自定义函数并将其传入:
function formatter($value) return number_format(floatval($value));
【讨论】:
感谢您的回复,是的,我知道没有什么好东西,因此我遇到了一个错误,无论如何我不是在问什么,而是如何? 见我上面的回复。基本上你是直接调用 number_format() 方法,但你需要一些中间的东西。因此,如果您将我编写的格式化程序函数复制/粘贴到您的代码中,您可以将该行更改为:$stats = array_map('formatter', $stats);
,它将起作用。基本上数据必须首先转换为浮点数。就是这样。
重读你的代码,$stats 会是数组的数组也是有问题的,你可以not把数组扔进number_format,floatval会让你很奇怪结果。你绝对应该在我上面写的格式化函数中做更多的数据按摩。
我会尝试使用您发送给我的代码 "$stats = array_map('formatter', $stats);"如果没有,我会从一个页面复制整个代码并粘贴到这里,谢谢!以上是关于PHP 警告:number_format() 期望参数 1 为浮点数的主要内容,如果未能解决你的问题,请参考以下文章