Page 1 of 1

How can I change the Array key ?

Posted: Wed Aug 16, 2006 12:09 pm
by Supper Baby
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have an array :

Code: Select all

$a[] = 'aaaa';
$a[] = 'bbbb';
$a[] = 'ccccc';
$a[] = 'dddd';
$a[] = 'eeee';
now I want to change the position of each array element.
I want to sort the array randomally

so the element key maybe:

Code: Select all

$a[3] = 'aaaa';
$a[1] = 'bbbb';
$a[5] = 'ccccc';
$a[2] = 'dddd';
$a[4] = 'eeee';
or

Code: Select all

$a[5] = 'aaaa';
$a[1] = 'bbbb';
$a[2] = 'ccccc';
$a[4] = 'dddd';
$a[3] = 'eeee';
or anything else


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Aug 16, 2006 12:12 pm
by feyd
shuffle() and array_rand() may be of interest.

Why are you posting your threads in PHPClasses.org's board?

Posted: Wed Aug 16, 2006 12:19 pm
by Luke
feyd wrote:Why are you posting your threads in PHPClasses.org's board?
I was wondering the same thing... I was going to answer, but then I saw it was in PHPClasses and thought maybe I didn't understand what they were asking.

Posted: Fri Aug 18, 2006 10:52 am
by Supper Baby
:) Thank you very much