# Array Help

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
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=>six);

whats the function used for any predefined array functions is there
for that.

## Re: Array Help

You could add it to the end of the array.

e.g

\$name.=3Darray(4=3D>four);

then use asort(\$name) to get it in the correct order.

Regards,
Alex

ajtrichards web solutions
www.ajtrichards.co.uk

## Re: Array Help

hi,

no need to add end of the array i want to add inter mediate the array
exactly given position .

## Re: Array Help

.oO(Damodhar)

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.

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