Home > Archive > PHP Language > March 2004 > how to keep index structure when imploding an array?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to keep index structure when imploding an array?
|
|
| Niels Laurens 2004-03-26, 11:13 pm |
| Hi,
Thanks for looking/anwsering my question.
Implode seems to implode on the 'sequence' of the inputed information, not
on the array index. Is there a short command for doing that ?
For example:
$test[0]=0;
$test[1]=1;
$test[2]=2;
$test[6]=6;
$test[3]=3;
$test[4]=4;
$test[5]=5;
echo implode(",", $test);
will return 0,1,2,6,3,4,5
while I want 0,1,2,3,4,5,6
I can solve this by making a 'fake' new array and implode that, but that
doesn't look nice code to me.
for ($i=0;$i<6;$i++)
$test_sorted[$i] = $test[$i];
echo implode(",", $test_sorted);
will now return 0,1,2,3,4,5,6
Thanks in advanced,
Niels Laurens
| |
| Jedi121 2004-03-26, 11:13 pm |
| Niels Laurens a écrit le 26/03/2004 :
> echo implode(",", $test);
> will return 0,1,2,6,3,4,5
>
> while I want 0,1,2,3,4,5,6
Use sort($test); before the implode();
| |
| Niels Laurens 2004-03-27, 11:53 pm |
| Thanks :)
"Jedi121" <jedi121news@free.fr.Removethis> wrote in message
news:mesnews.d55a7d43.55a599ed.627.2689@free.fr.Removethis...
> Niels Laurens a écrit le 26/03/2004 :
>
> Use sort($test); before the implode();
>
>
|
|
|
|
|