我要过滤某些条件下的数组。
我正在为我的旅行门户网站随机生成一组酒店,其中,基于位置的酒店的所有排列都应该出现。
条件是:- 1.在2个连续的夜晚中,在相同位置的夜晚只能获得相同的酒店和房型。
我的方法(我正在使用array_filter()):
public static function my_function($item_values)
{
for($i=0;$i<count($item_values);$i++){
if($i>0){
$j = $i-1;
$preData = explode('-',$item_values[$j]);
$data = explode('-',$item_values[$i]);
if($data[0] == $preData[0]){
if($data[1] == $preData[1]){
if($data[2] == $preData[2]){
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
} else {
return FALSE;
}
} else {
return true;
}
}
}
我的数组:
Array
(
[0] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-4-13
)
[1] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-100-271
)
[2] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-100-269
)
[3] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-202
[4] => 1-4-13
)
[4] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-202
[4] => 1-100-271
)
[5] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-202
[4] => 1-100-269
)
[6] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-76-203
[4] => 1-4-13
)
[7] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-76-203
[4] => 1-100-271
)
[8] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-76-203
[4] => 1-100-269
)
[9] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-56-116
[4] => 1-4-13
)
[10] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-56-116
[4] => 1-100-271
)
[11] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-56-116
[4] => 1-100-269
)
[12] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-295
[4] => 1-4-13
)
[13] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-295
[4] => 1-100-271
)
[14] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-295
[4] => 1-100-269
)
[15] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-55-84
[4] => 1-4-13
)
[16] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-55-84
[4] => 1-100-271
)
[17] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-55-84
[4] => 1-100-269
)
[18] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-115
[4] => 1-4-13
)
[19] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-115
[4] => 1-100-271
)
[20] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-115
[4] => 1-100-269
)
[21] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-4-13
)
[22] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-100-271
)
[23] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-100-269
)
[24] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-76-203
[4] => 1-4-13
)
[25] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-76-203
[4] => 1-100-271
)
[26] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-76-203
[4] => 1-100-269
)
[27] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-56-116
[4] => 1-4-13
)
[28] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-56-116
[4] => 1-100-271
)
[29] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-56-116
[4] => 1-100-269
)
[30] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-295
[4] => 1-4-13
)
[31] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-295
[4] => 1-100-271
)
[32] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-295
[4] => 1-100-269
)
[33] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-55-84
[4] => 1-4-13
)
[34] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-55-84
[4] => 1-100-271
)
[35] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-55-84
[4] => 1-100-269
)
[36] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-115
[4] => 1-4-13
)
[37] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-115
[4] => 1-100-271
)
[38] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-115
[4] => 1-100-269
)
[39] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-202
[4] => 1-4-13
)
[40] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-202
[4] => 1-100-271
)
[41] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-202
[4] => 1-100-269
)
[42] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-76-203
[4] => 1-4-13
)
[43] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-76-203
[4] => 1-100-271
)
[44] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-76-203
[4] => 1-100-269
)
[45] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-56-116
[4] => 1-4-13
)
[46] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-56-116
[4] => 1-100-271
)
[47] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-56-116
[4] => 1-100-269
)
[48] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-295
[4] => 1-4-13
)
[49] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-295
[4] => 1-100-271
)
[50] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-50-295
[4] => 1-100-269
)
[51] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-55-84
[4] => 1-4-13
)
[52] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-55-84
[4] => 1-100-271
)
[53] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-55-84
[4] => 1-100-269
)
[54] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-115
[4] => 1-4-13
)
[55] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-115
[4] => 1-100-271
)
[56] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-115
[4] => 1-100-269
)
[57] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-202
[4] => 1-4-13
)
[58] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-202
[4] => 1-100-271
)
[59] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-202
[4] => 1-100-269
)
[60] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-76-203
[4] => 1-4-13
)
[61] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-76-203
[4] => 1-100-271
)
[62] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-76-203
[4] => 1-100-269
)
[63] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-56-116
[4] => 1-4-13
)
[64] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-56-116
[4] => 1-100-271
)
[65] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-56-116
[4] => 1-100-269
)
[66] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-295
[4] => 1-4-13
)
[67] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-295
[4] => 1-100-271
)
[68] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-50-295
[4] => 1-100-269
)
[69] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-55-84
[4] => 1-4-13
)
[70] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-55-84
[4] => 1-100-271
)
[71] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-55-84
[4] => 1-100-269
)
[72] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-115
[4] => 1-4-13
)
[73] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-115
[4] => 1-100-271
)
[74] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-115
[4] => 1-100-269
)
[75] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-202
[4] => 1-4-13
)
[76] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-202
[4] => 1-100-271
)
[77] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-202
[4] => 1-100-269
)
[78] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-76-203
[4] => 1-4-13
)
[79] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-76-203
[4] => 1-100-271
)
[80] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-76-203
[4] => 1-100-269
)
[81] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-56-116
[4] => 1-4-13
)
[82] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-56-116
[4] => 1-100-271
)
[83] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-56-116
[4] => 1-100-269
)
[84] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-295
[4] => 1-4-13
)
[85] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-295
[4] => 1-100-271
)
[86] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-295
[4] => 1-100-269
)
[87] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-55-84
[4] => 1-4-13
)
[88] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-55-84
[4] => 1-100-271
)
[89] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-55-84
[4] => 1-100-269
)
[90] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-115
[4] => 1-4-13
)
[91] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-115
[4] => 1-100-271
)
[92] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-115
[4] => 1-100-269
)
[93] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-202
[4] => 1-4-13
)
[94] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-202
[4] => 1-100-271
)
[95] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-202
[4] => 1-100-269
)
[96] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-76-203
[4] => 1-4-13
)
[97] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-76-203
[4] => 1-100-271
)
[98] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-76-203
[4] => 1-100-269
)
[99] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-56-116
[4] => 1-4-13
)
[100] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-56-116
[4] => 1-100-271
)
[101] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-56-116
[4] => 1-100-269
)
[102] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-295
[4] => 1-4-13
)
[103] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-295
[4] => 1-100-271
)
[104] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-50-295
[4] => 1-100-269
)
[105] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-55-84
[4] => 1-4-13
)
[106] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-55-84
[4] => 1-100-271
)
[107] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-55-84
[4] => 1-100-269
)
[108] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-4-13
)
[109] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-100-271
)
[110] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-100-269
)
[111] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-202
[4] => 1-4-13
)
[112] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-202
[4] => 1-100-271
)
[113] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-202
[4] => 1-100-269
)
[114] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-76-203
[4] => 1-4-13
)
[115] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-76-203
[4] => 1-100-271
)
[116] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-76-203
[4] => 1-100-269
)
[117] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-56-116
[4] => 1-4-13
)
[118] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-56-116
[4] => 1-100-271
)
[119] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-56-116
[4] => 1-100-269
)
[120] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-295
[4] => 1-4-13
)
[121] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-295
[4] => 1-100-271
)
[122] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-295
[4] => 1-100-269
)
[123] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-55-84
[4] => 1-4-13
)
[124] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-55-84
[4] => 1-100-271
)
[125] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-55-84
[4] => 1-100-269
)
[126] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-115
[4] => 1-4-13
)
[127] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-115
[4] => 1-100-271
)
[128] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-115
[4] => 1-100-269
)
[129] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-4-13
)
[130] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-100-271
)
[131] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-100-269
)
[132] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-76-203
[4] => 1-4-13
)
[133] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-76-203
[4] => 1-100-271
)
[134] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-76-203
[4] => 1-100-269
)
[135] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-56-116
[4] => 1-4-13
)
[136] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-56-116
[4] => 1-100-271
)
[137] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-56-116
[4] => 1-100-269
)
[138] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-295
[4] => 1-4-13
)
[139] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-295
[4] => 1-100-271
)
[140] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-295
[4] => 1-100-269
)
[141] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-55-84
[4] => 1-4-13
)
[142] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-55-84
[4] => 1-100-271
)
[143] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-55-84
[4] => 1-100-269
)
[144] => Array
(
[1] => 1-100-271
[2] => 2-76-203
[3] => 2-50-115
[4] => 1-4-13
)
[145] => Array
(
[1] => 1-100-271
[2] => 2-76-203
[3] => 2-50-115
[4] => 1-100-271
)
...
)
因此,在数组元素[1] => 1-100-269中表示为:
[1] ==键和夜晚。 1是位置ID。 酒店ID为100 房间类型ID 269。
我希望在不同的夜晚,同一地点的阵列酒店和房间类型相同。但是我得到了所有323个数组元素。
感谢您的帮助。
我的期望数组:
Array
(
[0] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-4-13
)
[1] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-100-271
)
[2] => Array
(
[1] => 1-4-13
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-100-269
)
[3] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-4-13
)
[4] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-100-271
)
[5] => Array
(
[1] => 1-4-13
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-100-269
)
[6] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-76-203
[4] => 1-4-13
)
[7] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-76-203
[4] => 1-100-271
)
[8] => Array
(
[1] => 1-4-13
[2] => 2-76-203
[3] => 2-76-203
[4] => 1-100-269
)
[9] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-56-116
[4] => 1-4-13
)
[10] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-56-116
[4] => 1-100-271
)
[11] => Array
(
[1] => 1-4-13
[2] => 2-56-116
[3] => 2-56-116
[4] => 1-100-269
)
[12] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-295
[4] => 1-4-13
)
[13] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-295
[4] => 1-100-271
)
[14] => Array
(
[1] => 1-4-13
[2] => 2-50-295
[3] => 2-50-295
[4] => 1-100-269
)
[15] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-55-84
[4] => 1-4-13
)
[16] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-55-84
[4] => 1-100-271
)
[17] => Array
(
[1] => 1-4-13
[2] => 2-55-84
[3] => 2-55-84
[4] => 1-100-269
)
[18] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-4-13
)
[19] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-100-271
)
[20] => Array
(
[1] => 1-100-271
[2] => 2-50-115
[3] => 2-50-115
[4] => 1-100-269
)
[21] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-4-13
)
[22] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-100-271
)
[23] => Array
(
[1] => 1-100-271
[2] => 2-50-202
[3] => 2-50-202
[4] => 1-100-269
)
)