我正在使用array_push()
方法从我的数据库中插入 id。
例子:
print_r($arr_usr_ids);
Array ( [0] => 34 [1] => 35 [2] => 34 [3] => 37 [4] => 38 [5] => 30 ... )
$arr_usrs = array();
foreach($arr_usr_ids as $key => $value) {
if(isset($group_id[1]) && '1'=== $group_id[0]) {
$numbers = $arr_usr_ids[$key]; // 30
$arr_usrs[] = $numbers;
} else
if(isset($group_id[1]) && '2'=== $group_id[0]) {
$numbers = $arr_usr_ids[$key]; // 34,33
$arr_usrs[] = $numbers;
}
...
}
等等...
但 array_push 正在订购数字
print_r($arr_usrs);
Array ( [0] => 30 [1] => 33 [2] => 34 [3] => 37 [4] => 38 )
正确的结果是 30,34,33,38,37
编辑这个作品:
$arr_usrs_one = array();
$arr_usrs_two = array();
$arr_usrs_three = array();
foreach($arr_usr_ids as $key => $value) {
if(isset($group_id[1]) && '1'=== $group_id[0]) {
$numbers = $arr_usr_ids[$key]; // 30
$arr_usrs_one[] = $numbers;
} else
if(isset($group_id[1]) && '2'=== $group_id[0]) {
$numbers = $arr_usr_ids[$key]; // 34,33
$arr_usrs_two[] = $numbers;
}
...
}
$result_usrs = array_merge($arr_usrs_one,$arr_usrs_two,$arr_usrs_three);