Jump to content

How can I get the index values of an array into a new array?


Recommended Posts

Here is the kind of array I have, sorted by the 'score':

$players['george'] = 81;

$players['simon'] = 74;

$players['sally'] = 44;

...

 

Now I am in the middle of an array, And I want to print out the 'name' with the score:

foreach($players as $player){

    echo ???NAME???.' -- '.$player.'</br>';

}

 

I want it to output like so

george -- 81

simon -- 74

sally -- 44

 

 

 

So could anyone please tell me how I can get the values? I know there is some function that will make me a new array with the index values, but I can't remember it...

$namearray = mysteryfunction($players);

and $namearray would be

$namearray[0] = "george";

$namearray[1] = "simon";

$namearray[2] = "sally";

...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.