Sorting multi dimensional array with a certain key

Get help on web editors (Frontpage, Dreamweaver) and web languages (HTML, ASP, PHP).
Post Reply
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Sorting multi dimensional array with a certain key

Post by DarkRanger »

I have the following:

Code: Select all

$resultArray[$c]['id'];
$resultArray[$c]['filename'];
$resultArray[$c]['keywords'];
$resultArray[$c]['matchPercentage'];
How do I sort this array by $resultArray[$c]['matchPercentage'] from high to low?
Image
D3PART3D
Starbound's Dear
Posts: 16295
Joined: 01 Dec 2004, 02:00
Contact:

Re: Sorting multi dimensional array with a certain key

Post by D3PART3D »

Wow, awesome thread title.
Ceterum autem censeo Samsung Mobile esse delendam.

When something is important enough, you do it even if the odds are not in your favor.
- Elon Musk
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: Sorting multi dimensional array with a certain key

Post by DarkRanger »

What should I have named it? :P
Image
D3PART3D
Starbound's Dear
Posts: 16295
Joined: 01 Dec 2004, 02:00
Contact:

Re: Sorting multi dimensional array with a certain key

Post by D3PART3D »

No, I mean Star Trek awesome.
Ceterum autem censeo Samsung Mobile esse delendam.

When something is important enough, you do it even if the odds are not in your favor.
- Elon Musk
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: Sorting multi dimensional array with a certain key

Post by Bladerunner »

DarkRanger wrote:I have the following:

Code: Select all

$resultArray[$c]['id'];
$resultArray[$c]['filename'];
$resultArray[$c]['keywords'];
$resultArray[$c]['matchPercentage'];
How do I sort this array by $resultArray[$c]['matchPercentage'] from high to low?
Are you looking for something along the lines of Array.Sort ( :P ) or are you actually interested in implementing an algorithm like Bubble-, Selection-, Insertion-, or Quicksort?
If I weren't insane: I couldn't be so brilliant! - The Joker
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: Sorting multi dimensional array with a certain key

Post by DarkRanger »

Just want something basic. So along the lines of array.sort will be fine!
Image
Post Reply