PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Array
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Array

Réponse
 
LinkBack Outils de la discussion
Vieux 24/03/2008, 22h41   #1
Damodhar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Array

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.
  Réponse avec citation
Vieux 24/03/2008, 22h55   #2
ajtrichards@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Array

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
  Réponse avec citation
Vieux 24/03/2008, 23h35   #3
Damodhar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Array

hi,

no need to add end of the array i want to add inter mediate the array
exactly given position .
  Réponse avec citation
Vieux 25/03/2008, 19h34   #4
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Array

..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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h11.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10502 seconds with 12 queries