Jump to content

how to connect values and keys and then sort them?


tastro

Recommended Posts

ok this works fine now... but some of my numbers are the same also like this:

 

$a=array('juice','milk','cola','sprite');

$a2=array('1','3','2','3');

 

and then the second key with the same number doesn't get printed out. :S

 

if you fix this then all will work perfect. :>

 

thank you both for the one before, both worked.

Link to comment
Share on other sites

also to explain it more... i have a ranking system on my site... from rank 1 to rank 5. and some users have the same rank, also there are more users with rank 2 and 3... and i have to sort theyr posts by theyr rank.

 

'juice','milk','cola','sprite' <--- this are the post titles

 

'1','3','2','3' <--- and this are the rankings of the users who made the posts

Link to comment
Share on other sites

don't know how to do this.

 

but i found another way myself right now:

 

$ar1=array('1','3','2','3');
$ar2=array('juice','milk','cola','sprite');
array_multisort($ar1,$ar2);
print_r($ar2);

 

i didn't knew that this function even exists: array_multisort();

 

but would like to see your idea as well please (maybe it's faster or uses less resources). thank you. ;)

Link to comment
Share on other sites

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.