Skip to content
Advertisement

How to take array object from the array object based on the highest value by a column in php

I have the following array, and each element of the array has a priority element. Based on the maximum priority value how can we generate the new array?

JavaScript

Thus the highest priority value here 3. So, the result array will be like the following. Can you help me please. Thank you in advance.

JavaScript

Advertisement

Answer

You could use usort to sort your array by priority descending, and then make an array of the [0] element:

JavaScript

Output:

JavaScript

Demo on 3v4l.org

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