Wednesday 13 July 2016

How to sort a Multidimensional Array based on a value in PHP?

Let's consider $contents is the Multidimensional Array which needs to get sort based on a 'info' value
$sorted_data = array();
    foreach ($contents as $key => $content) {
    $sorted_data[$key]  = $content['info'];
    }
array_multisort($sorted_data, SORT_ASC, $contents);
Here, array_multisort will sort $contents variable based on 'info' value.

No comments:

Post a Comment

Your comment is so valuable as it would help me in my growth of knowledge.