0

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:

example array structure

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?

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.