Hello people, just a quick question I have here.
My array looks like this:
[PHP]Array (
[0] => Array (
[id] => 15
[site_url] => example.com
[clean_url] => examplecom
[code] => NshKsi23
[success] => 1
[fail] => 1
[success_rate] => 50
[fail_rate] => 50
[description] => Free delivery.
[validfrom] => Not Set
[validto] => 18 / 02 / 10 )
[1] => Array (
[id] => 14
[site_url] => example.com
[clean_url] => examplecom
[code] => NshKsi23
[success] => 2
[fail] => 0
[success_rate] => 100
[fail_rate] => 0
[description] => free delivery.
[validfrom] => 01 / 02 / 05
[validto] => 14 / 04 / 08 )
[2] => Array (
[id] => 13
[site_url] => example.com
[clean_url] => examplecom
[code] => NshKsi23
[success] => 2
[fail] => 0
[success_rate] => 100
[fail_rate] => 0
[description] => free delivery.
[validfrom] => Not Set
[validto] => Not Set)
) [/PHP]
I was wondering is there a way to sort this data by the "success_rate" in each of those arrays. So the data would be displayed like so:
[PHP]Array (
[0] => Array (
[id] => 14
[site_url] => example.com
[clean_url] => examplecom
[code] => NshKsi23
[success] => 2
[fail] => 0
[success_rate] => 100
[fail_rate] => 0
[description] => free delivery.
[validfrom] => 01 / 02 / 05
[validto] => 14 / 04 / 08 )
[1] => Array (
[id] => 13
[site_url] => example.com
[clean_url] => examplecom
[code] => NshKsi23
[success] => 2
[fail] => 0
[success_rate] => 100
[fail_rate] => 0
[description] => free delivery.
[validfrom] => Not Set
[validto] => Not Set)
[2] => Array (
[id] => 15
[site_url] => example.com
[clean_url] => examplecom
[code] => NshKsi23
[success] => 1
[fail] => 1
[success_rate] => 50
[fail_rate] => 50
[description] => Free delivery.
[validfrom] => Not Set
[validto] => 18 / 02 / 10 )
) [/PHP]
Thanks a lot if anyone can help me.
EDIT: and just so you know, the success_rate is worked out in PHP and is not stored in the database so I can not use ORDER BY in my MySQL statement. Thanks for your time.
5 1493
Heya, Anthony.
To do this, you need to use array_multisort().
First, you need to create a temporary array that maps keys to values: -
$__map = array();
-
foreach( $array as $__key => $__subArray )
-
{
-
$__map[$__key] = $__subArray['success_rate'];
-
}
-
Then, pass the array to array_multisort() like this: -
array_multisort($__map, SORT_DESC, $array);
-
Hey pbmods
i was just wondering, why do you do variables like so:
[php]
$__someVariable
[/php]
:)
Thanks and sorry for the late reply.
I will have a mess with your method after Christmas and try to implement it. I looked through the different sorts on the php website but things got confusing lol.
Thanks very much for your time :)
Heya, Anthony.
Yeah, array_multisort() is pretty confusing.
Good luck with your project, and if you run into any trouble, post back anytime :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shaunak Kashyap |
last post by:
Does anyone know what sorting algorithm(s) -- quicksort, mergesort,
radix sort, etc. -- does PHP use internally in its sort function?
|
by: Eva |
last post by:
Hi,
I try to implement quick sort. I sort vectors by their first value.
10 2 3 4
9 3 5 6
10 4 5 6
must be
9 3 5 6
10 2 3 4
10 4 5 6
The prog works great on maybe 500 vectors, but I have an...
|
by: GIMME |
last post by:
My question is ... How do I sort an Array on numeric, not character values ?
In the example below, after sorting the contents are 1,10,2,3 .
How do I get the contents to be 1,2,3,10 ?
...
|
by: Frank King |
last post by:
Hi,
I am using CArray and quick sort funciton to sort an array
of double type of data points. I found an article in MSDN
HOWTO: Quick Sorting Using MFC CArray-Derived Classes
ID: Q216858
...
|
by: Gerrit |
last post by:
Hello,
Is it possible to sort an array with a struct in it?
example:
I have a struct:
public struct mp3file
{
public int tracknr;
|
by: Alex Chudnovsky |
last post by:
I have come across with what appears to be a significant performance bug in
..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same
data. Same data on the same CPU gets sorted a...
|
by: ralphedge |
last post by:
These sorts work fine on 100000 ints but if I go much higher they will
both segmentation fault
**************************MERGESORT*********************
mergesort(int *a, int size) //a is...
|
by: JosAH |
last post by:
Greetings,
I was asked to write a Tip Of the Week; so here goes: a lot of topics are
started here in this forum (and a lot of other forums too) mentioning a
problem about sorting data.
...
|
by: feverzsj |
last post by:
STL sort() as an implementation of introsort, below is the code
snippet from the gnu stl.
template<typename _RandomAccessIterator, typename _Size>
void
__introsort_loop(_RandomAccessIterator...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |