Page 1 of 1
insert into array
Posted: Thu Jun 02, 2005 1:29 am
by shiznatix
Ok i have to insert into a key and value into a array between 2 keys. i have keys 1 and 3 but after thats made i need to be able to insert a key 2 between the 2. when i do $arr['2'] = $some_var then it just inserts it after key 3 but i cant have that.
Posted: Thu Jun 02, 2005 2:07 am
by anjanesh
array_multisort works only for numeric keys.
Code: Select all
<?php
$arr = array();
$arr[0]="a";
$arr[2]="c";
$arr[1]="b";
array_multisort($arr);
while (list($k,$v)=each($arr))
{
echo $k.' : '.$v.'<br>';
}
?>
Posted: Thu Jun 02, 2005 4:24 am
by shiznatix
how can i keep the original keys? they are numeric keys
Posted: Thu Jun 02, 2005 4:49 am
by anjanesh
Output is
0 : a
1 : b
2 : c
Original keys intact.