且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在PHP中获取和生成重复数字(子集)数组

更新时间:2023-02-23 10:45:32

一个获得结果的选项是使用resul将另一个值传递给array_map的 array_count_values

One option to get your result is to pass another value to array_map with the result of array_count_values.

然后,您可以在映射内确定基于索引的数字计数,例如 $ countValues [$ x] 和映射器一样。

Then inside the mapping you can determine to show the count for the number based on the index like $countValues[$x] just as for the mapper.

例如

foreach($out as $result) {
    $countValues = array_count_values($result);
    echo "<b>Possible Answer " . $m++ . " : </b><br> " . implode(' , ',
            array_map(function ($x) use ($mapper, $countValues) {
                $strCount = $countValues[$x] > 1 ? " (" . $countValues[$x] . ")" : "";
                return $mapper[$x] . $strCount . " - " . $x;
            }, array_unique($result))) . "
      <br><br>";
}

这将为您提供类似

Possible Answer 1 :
Level 2 - 23 , Level 6 - 68 , Level 7 (x2) - 79 , Level 9 - 101 , Level 10 - 112 , Level 15 - 168 

Php演示 $ array