Reputation: 3446
I am more of a JS person so I wrote a page using JS. However, I later realized it would probably be better to do 99.9% of the stuff I needed to do server-side, but being rather new to PHP I need some help.
Below is a snippet where I create basically a multi-dimensional array and sort it by one of its inner values:
var sortedpts=[];
_.each(main.points,function(v,k){
sortedpts.push([k,v]);
});
sortedpts.sort(function(a,b){return b[1]-a[1];});
return sortedpts;
The whole structure is a long array (over 100 values) where each key contains an array of two values and I wish to sort by the latter of these. If you're confused here is a screenshot/example showing how my JS has sorted the main array by an inner value:
I'm kind of at a loss of how to sort this particular way in PHP. It seems that array_multisort may be involved in the solution. Any help?
Upvotes: 0
Views: 599
Reputation: 324630
Since I gather all you needed was to be pointed to the right function, here it is again:
JavaScript's "sort by function" is more or less exactly the same as PHP's usort
. There are some minor differences (such as how PHP anonymous functions don't inherit the parent scope), but that's not really relevant here.
Upvotes: 1