|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
hi,
any one say how to insert the value intermediate the array. for example one array having value like $name = array(1=>one,2=>two,3=>three,5=>five,6=>six); i want to insert " 4=>four " in the above array the result will be come like $name = array(1=>one,2=>two,3=>three,4=>four,5=>five,6=>si x); whats the function used for any predefined array functions is there for that. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Mar 24, 9:41pm, Damodhar <damu...@gmail.com> wrote:
> hi, > > any one say how to insert the value intermediate the array. > > for example one array having value like > > $name = array(1=>one,2=>two,3=>three,5=>five,6=>six); > > i want to insert " 4=>four " in the above array > > the result will be come like > > $name = array(1=>one,2=>two,3=>three,4=>four,5=>five,6=>si x); > > whats the function used for any predefined array functions is there > for that. You could add it to the end of the array. e.g $name.=array(4=>four); then use asort($name) to get it in the correct order. Regards, Alex ajtrichards web solutions www.ajtrichards.co.uk |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
hi,
no need to add end of the array i want to add inter mediate the array exactly given position . |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
..oO(Damodhar)
>no need to add end of the array i want to add inter mediate the array >exactly given position . PHP arrays don't have a fixed order. You add new elements to the beginning or end of the array and then sort it the way you want. Given your example array: Array ( [1] => one [2] => two [3] => three [5] => five [6] => six ) Add a new element with the key 4: $name[4] = 'four'; Array ( [1] => one [2] => two [3] => three [5] => five [6] => six [4] => four ) Then sort the array: ksort($name); Array ( [1] => one [2] => two [3] => three [4] => four [5] => five [6] => six ) HTH Micha |
|
![]() |
| Outils de la discussion | |
|
|