Skip to content
Advertisement

Sorting an associative array with a string in PHP

I’m working on a php issue with an associative array and attempting to sort it. What I have looks something like this:

JavaScript

I want to sort it so it looks like this:

JavaScript

I’ve thought about exploding along the | and then taking the 0.0.0.111 and comparing it to everything else. What I tried look like this:

JavaScript

I realized though that I comparing the whole: 0.0.1.222|ed7e434b79e54834440101fc07cc0981|Apples

instead of the first part 0.0.1.222. Thank you for any help.

Advertisement

Answer

Try array_map('sort', $yourMainArray); or run your own callback on the map or even a simple loop and sort would do it.

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