我确信这很简单,我只是无法为谷歌正确措辞。希望我能在这里说得足够清楚,有人可以指出我正确的方向!
我正在使用php和chart.js来绘制有关综合格斗选手的统计数据,我想绘制他们每年有多少胜利(或失败或ko等)。
我已经能够创建一个数组来显示每次损失的年份(请注意,一年内发生了多次损失)
例如
$loss_years = Array ( [0] => 2019 [1] => 2016 [2] => 2014 [3] => 2013 [4] => 2012 [5] => 2011 [6] => `2011 [7] => 2010 [8] => 2009 [9] => 2009 [10] => 2006 [11] => 2005 )`
我已经能够计算出每年发生多少损失,损失确实是这样的:
array_count_values(array_reverse ($loss_years)));
哪些输出:
array(10) { ["2005 "]=> int(1) ["2006 "]=> int(1) ["2009 "]=> int(2) ["2010 "]=> int(1) ["2011 "]=> int(2) ["2012 "]=> int(1) ["2013 "]=> int(1) ["2014 "]=> int(1) ["2016 "]=> int(1) ["2019 "]=> int(1) }
但是,我希望能够与他们职业生涯的每一年进行交叉引用。
因此,如果他们的职业生涯表示为:
$career_span = Array ( [0] => 2004 [1] => 2005 [2] => 2006 [3] => 2007 [4] => 2008 [5] => 2009 [6] => 2010 [7] => 2011 [8] => 2012 [9] => 2013 [10] => 2014 [11] => 2015 [12] => 2016 [13] => 2017 [14] => 2018 [15] => 2019 [16] => 2020 )
然后我想用 $loss_years 交叉引用它,并输出第三个数组 $losses_per_year,如下所示:
Array ( [0] => 0 [1] => 1 [2] => 1 [3] => 0 [4] => 0 [5] => 2 [6] => 1 [7] => 2 [8] => 1 [9] => 1 [10] => 1 [11] => 0 [12] => 1 [13] => 0 [14] => 0 [15] => 1 [16] => 0 )
这有意义吗?
有没有一些更简单的方法可以解决它,我没有找到?
喵喵时光机