【问题标题】:PHP - APRIORI - How to display a combination that meets the support value?PHP - APRIORI - 如何显示满足支持值的组合?
【发布时间】:2017-12-05 10:04:48
【问题描述】:

我想显示一个大于支持值的组合值,假设支持值 4 那么将只显示大于 4 的组合。 我附上代码:

for($i = 0; $i < $item1; $i++) 
{
    for($j = $i+1; $j < $item2; $j++) 
    {
        $hasil = 0;
        $item_pair = $item[$i].'|'.$item[$j];
        $item_array[$item_pair] = $hasil;
        foreach($belian as $item_belian) 
        {
            if((strpos($item_belian, $item[$i]) !== false) && (strpos($item_belian, $item[$j]) !== false)) 
            {
                $item_array[$item_pair]++;
            }
        }
    }
}

这是上面代码的结果,红线中还有一个小于支持值的组合值,如何防止组合不显示。

结果

【问题讨论】:

  • 查看您输入的内容可能很有用

标签: php codeigniter codeigniter-3


【解决方案1】:

为了更快的解决方案,我相信您可以使用array keys 来返回 $item_array 中值小于支持值的所有键。为数组赋值后放置它。

$support_value = 4 // this is just for an example, use your own value.
$keys = array_keys($item_array, $support_value); // to get all the item pair that has value < support value

// to delete all the item pair that has value < support value
foreach($keys as $key){
    unset($item_array[$key]);
}

来源:Search value in php array and get all keys

【讨论】:

  • 在你给$item_array赋值完之后放上代码。我已经编辑了我的答案
猜你喜欢
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
  • 2019-12-21
  • 1970-01-01
  • 1970-01-01
  • 2021-05-19
  • 2012-05-09
  • 1970-01-01
相关资源
最近更新 更多