我试图在谷歌的各个地方找到答案,但无法找到一个看起来像我的问题的匹配。 我目前正在开发一个预约系统,其数据来自外部系统。
在我的系统中,可以选择"产品"和数量。以下是选定产品的示例:
A0004 2x(预约长度= 10分钟,总共20分钟)
A0010 1x(预约长度= 5分钟)
来自外部系统的API要求我按产品请求可用的日期和时间。因此,当我这样做时,我有一个包含2个产品及其可用性的阵列。例如:
(日期时间实际上是时间戳,但我希望在此示例中使其更具视觉效果)
Array ( [A0004] => Array ( [0] => 30-10-2014 09:20:00 [1] => 30-10-2014 09:30:00 [2] => 30-10-2014 15:20:00 [3] => 30-10-2014 15:30:00 [4] => 30-10-2014 16:30:00 [5] => 30-10-2014 17:10:00 [6] => 30-10-2014 17:20:00 [7] => 30-10-2014 17:30:00 [8] => 30-10-2014 18:10:00 [9] => 30-10-2014 18:20:00 [10] => 30-10-2014 18:30:00 [11] => 31-10-2014 09:00:00 [12] => 31-10-2014 09:10:00 [13] => 31-10-2014 09:20:00 [14] => 31-10-2014 12:20:00 [15] => 03-11-2014 09:10:00 [16] => 03-11-2014 09:20:00 [17] => 03-11-2014 09:30:00 [18] => 03-11-2014 10:10:00 [19] => 03-11-2014 10:20:00 [20] => 03-11-2014 12:10:00 [21] => 03-11-2014 12:20:00 [22] => 03-11-2014 12:30:00 [23] => 03-11-2014 13:00:00 [24] => 03-11-2014 13:10:00 [25] => 03-11-2014 13:20:00 [26] => 03-11-2014 14:00:00 [27] => 03-11-2014 14:10:00 [28] => 03-11-2014 14:20:00 [29] => 03-11-2014 14:30:00 [30] => 03-11-2014 15:10:00 [31] => 03-11-2014 15:20:00 [32] => 03-11-2014 15:30:00 [33] => 03-11-2014 16:00:00 [34] => 03-11-2014 16:10:00 [35] => 03-11-2014 16:20:00 [36] => 03-11-2014 16:30:00 [37] => 03-11-2014 17:00:00 [38] => 03-11-2014 17:10:00 [39] => 03-11-2014 17:20:00 ) [A0010] => Array ( [0] => 29-10-2014 15:15:00 [1] => 29-10-2014 15:40:00 [2] => 29-10-2014 16:35:00 [3] => 29-10-2014 16:40:00 [4] => 29-10-2014 17:10:00 [5] => 29-10-2014 17:15:00 [6] => 29-10-2014 17:20:00 [7] => 29-10-2014 17:40:00 [8] => 30-10-2014 09:20:00 [9] => 30-10-2014 09:25:00 [10] => 30-10-2014 09:30:00 [11] => 30-10-2014 09:35:00 [12] => 30-10-2014 09:40:00 [13] => 30-10-2014 10:10:00 [14] => 30-10-2014 10:25:00 [15] => 30-10-2014 10:40:00 [16] => 30-10-2014 11:05:00 [17] => 30-10-2014 11:40:00 [18] => 30-10-2014 12:25:00 [19] => 30-10-2014 12:40:00 [20] => 30-10-2014 13:40:00 [21] => 30-10-2014 14:10:00 [22] => 30-10-2014 14:40:00 [23] => 30-10-2014 15:20:00 [24] => 30-10-2014 15:25:00 [25] => 30-10-2014 15:30:00 [26] => 30-10-2014 15:35:00 [27] => 30-10-2014 15:40:00 [28] => 30-10-2014 16:15:00 [29] => 30-10-2014 16:20:00 [30] => 30-10-2014 16:30:00 [31] => 30-10-2014 16:35:00 [32] => 30-10-2014 16:40:00 [33] => 30-10-2014 17:10:00 [34] => 30-10-2014 17:15:00 [35] => 30-10-2014 17:20:00 [36] => 30-10-2014 17:25:00 [37] => 30-10-2014 17:30:00 [38] => 30-10-2014 17:35:00 [39] => 30-10-2014 17:40:00 [40] => 30-10-2014 18:05:00 [41] => 30-10-2014 18:10:00 [42] => 30-10-2014 18:15:00 [43] => 30-10-2014 18:20:00 [44] => 30-10-2014 18:25:00 [45] => 30-10-2014 18:30:00 [46] => 30-10-2014 18:35:00 [47] => 30-10-2014 18:40:00 [48] => 30-10-2014 19:15:00 [49] => 30-10-2014 20:40:00 [50] => 31-10-2014 09:00:00 [51] => 31-10-2014 09:05:00 [52] => 31-10-2014 09:10:00 [53] => 31-10-2014 09:15:00 [54] => 31-10-2014 09:20:00 [55] => 31-10-2014 09:25:00 [56] => 31-10-2014 09:40:00 [57] => 31-10-2014 10:25:00 [58] => 31-10-2014 10:35:00 [59] => 31-10-2014 11:35:00 [60] => 31-10-2014 11:40:00 [61] => 31-10-2014 12:20:00 [62] => 31-10-2014 12:25:00 [63] => 03-11-2014 09:05:00 [64] => 03-11-2014 09:10:00 [65] => 03-11-2014 09:15:00 [66] => 03-11-2014 09:20:00 [67] => 03-11-2014 09:25:00 [68] => 03-11-2014 09:30:00 [69] => 03-11-2014 09:35:00 [70] => 03-11-2014 09:40:00 [71] => 03-11-2014 10:05:00 [72] => 03-11-2014 10:10:00 [73] => 03-11-2014 10:15:00 [74] => 03-11-2014 10:20:00 [75] => 03-11-2014 10:25:00 [76] => 03-11-2014 10:40:00 [77] => 03-11-2014 11:25:00 [78] => 03-11-2014 11:40:00 [79] => 03-11-2014 12:05:00 [80] => 03-11-2014 12:10:00 [81] => 03-11-2014 12:15:00 [82] => 03-11-2014 12:20:00 [83] => 03-11-2014 12:25:00 [84] => 03-11-2014 12:30:00 [85] => 03-11-2014 12:35:00 [86] => 03-11-2014 12:40:00 [87] => 03-11-2014 13:00:00 [88] => 03-11-2014 13:05:00 [89] => 03-11-2014 13:10:00 [90] => 03-11-2014 13:15:00 [91] => 03-11-2014 13:20:00 [92] => 03-11-2014 13:25:00 [93] => 03-11-2014 13:35:00 [94] => 03-11-2014 13:40:00 [95] => 03-11-2014 14:00:00 [96] => 03-11-2014 14:05:00 [97] => 03-11-2014 14:10:00 [98] => 03-11-2014 14:15:00 [99] => 03-11-2014 14:20:00 ) ) 1
根据上述信息,我应该生成一系列时间段,这两个产品可以预约(数量为3个)。
一句话,可以选择2件以上的产品和2件以上的产品,因此必须灵活。
因此,总结:产品A0004已被选中两次,因此必须连续两次(总共20分钟)可用时间段,而另一产品必须连接该时间段(之前或之后)是可能的)。最终结果必须是一个包含可用时隙的数组。
有没有人知道如何才能让它发挥作用?特别是具有所选产品的数量和数量的灵活性。