arrays - PHP array_push() without ordering -


i using array_push() method insert ids database.

example:

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 $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; }  ... } 

and on...

but array_push ordering numbers

print_r($arr_usrs); array ( [0] => 30 [1] => 33 [2] => 34 [3] => 37 [4] => 38 )  

the correct result 30,34,33,38,37

edit works:

$arr_usrs_one = array(); $arr_usrs_two = array(); $arr_usrs_three = array();  foreach($arr_usr_ids $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); 

just change array_push []:

$arr_usrs = array();  if(isset($group_id[1]) && '1'=== $group_id[0]) {  $numbers = $arr_usr_ids; // 30  $arr_usrs[] = $numbers; }  if(isset($group_id[1]) && '2'=== $group_id[0]) {  $numbers = $arr_usr_ids; // 34,33  $arr_usrs[] = $numbers; } print_r($arr_usrs); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -