I have an array with 2 dimensions, the first dimension has the name of a company, the second the hits of their website.
I want to sort the entire array (not each dimension) with the hits (numbers).
How can I do it?
Dimis
| SitePoint Sponsor |




I have an array with 2 dimensions, the first dimension has the name of a company, the second the hits of their website.
I want to sort the entire array (not each dimension) with the hits (numbers).
How can I do it?
Dimis
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget


http://us.php.net/usortPHP Code:function cmp($a, $b) {
if ($a[1] == $b[1]) {
return 0;
}
return ($a[1] < $b[1]) ? -1 : 1;
}
$a = array(
array('site1', 100),
array('site2', 200),
array('site3', 50)
);
usort($a, "cmp");
If this isn't how your array is set up (your description is ambiguous), then you need to adjust the cmp function to match.
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.




My array is
Code:$data=array(); $data[1][0]='name 1';$data[1][1]=125; $data[2][0]='name 2';$data[2][1]=188; $data[3][0]='name 3';$data[3][1]=118; ...


Why is 118 not [3][1]? If those indexes are right, there's no structure here at all...
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.




It was a typing error,


Then the code I gave you should work. Try it out.
17-29% of paid ad clicks are fraudulent. Get protected with Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more.
Bookmarks