Skip to content
Advertisement

How can I sort an array stating in a given number

First of all I am new in php. I need help to sort an array.

I have an array of ID’s and zip codes like this:

JavaScript

Now I have a number lets say ‘2900’ I would like to sort my array from the closest number (2900) to the most distant.

Example: the number is 2900. So the array should sort like this:

JavaScript

Can someone help me?

Thank you

Advertisement

Answer

I guess, you can use function uksort in next way:

JavaScript

Check PHP code here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement