我有一个相当奇怪的问题。我有一个应用程序,它需要一组介于 1 和 6 之间的数字。它们可以是任意数量的模式。从那里,我希望它们以特定的方式格式化。这有点难以解释,所以我只给你一些例子:
[1] -> "1" (duh!)
[1, 3] -> "1,3" (any two values will be separated by commas)
[1, 2, 3] -> "1-3" (consecutive series: lowest and highest values separated by a dash)
[1, 3, 4] -> "1, 3, 4" (non-consecutive series: separated by commas)
[1, 2, 3, 5, 6] -> 1-3, 5, 6" (mixed: consecutive series and non-consecutive series as you see)
其他几个参数:
- 数组中的每一项都是唯一的
- 该列表将被预先排序
该应用程序是用 PHP 编写的。任何帮助将不胜感激。