How can I change the Array key ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Supper Baby
Forum Commoner
Posts: 27
Joined: Tue Aug 01, 2006 11:33 pm

How can I change the Array key ?

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

shuffle() and array_rand() may be of interest.

Why are you posting your threads in PHPClasses.org's board?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
Supper Baby
Forum Commoner
Posts: 27
Joined: Tue Aug 01, 2006 11:33 pm

Post by Supper Baby »

:) Thank you very much
Post Reply