0

There is scenaria when I fetch results from mysql table using PHP. The results have a column named as status. That column has multiple values like follow up, won and lost. I want to show the results in this order using PHP

  • Follow up
  • Won
  • Lost

How can I achieve this?

I am looking at PHP sort functions but not getting the result I want. So need a solution to get the results in the same way I mentioned.

  • Does this answer your question? [sql ORDER BY multiple values in specific order?](https://stackoverflow.com/questions/6332043/sql-order-by-multiple-values-in-specific-order) – Đào Minh Hạt Nov 30 '22 at 03:23
  • I want to show the results from PHP object, don't want to do it using query. – Upendra Sharma Nov 30 '22 at 06:02
  • SQL does it much better for the performance with a large dataset. But if you really need to do it in PHP you can use `usort` https://www.php.net/manual/en/function.usort.php – Đào Minh Hạt Dec 02 '22 at 03:34

1 Answers1

0

This is the trick for the above

$sortvalue = 'Follow up';
$result = array_filter($results, function ($item) use ($sortvalue) {
            if(stripos($item['status'], $sortvalue) !== false) {
                return true;
            }
            return false;
        });
var_dump($result);