3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[ { "id": "1", "country_id": "1", "spec_id": "1", "spec_children_name": "SUPER REDUCES RATE", "spec_children_first_col": "", "spec_children_second_col": "", "spec_children_third_col": "" }, { "id": "2", "country_id": "1", "spec_id": "1", "spec_children_name": "REDUCED RATE", "spec_children_first_col": "10% and 13%", "spec_children_second_col": "food, passenger transport, accommodotion, newspaper, pharmaceutical products,\u2026.(10%); plants, antiques, firewood, cinema, theatre,\u2026(13%)", "spec_children_third_col": "" }, { "id": "3", "country_id": "1", "spec_id": "1", "spec_children_name": "MEDIUM RATE", "spec_children_first_col": "", "spec_children_second_col": "", "spec_children_third_col": "" }, { "id": "4", "country_id": "1", "spec_id": "1", "spec_children_name": "STANDARD RATE", "spec_children_first_col": "20%", "spec_children_second_col": "other", "spec_children_third_col": "" }, { "id": "5", "country_id": "1", "spec_id": "1", "spec_children_name": "ZERO RATE", "spec_children_first_col": "", "spec_children_second_col": "", "spec_children_third_col": "" }, { "id": "104", "country_id": "2", "spec_id": "1", "spec_children_name": "REDUCED RATE", "spec_children_first_col": "TEXT 547", "spec_children_second_col": "TEXT 1000", "spec_children_third_col": "" } ]'; $objects = json_decode($json); $rules = ['spec_id' => 'ASC', 'spec_children_name' => 'DESC']; uasort($objects, function($a, $b) use ($rules) { foreach ($rules as $column => $order) { $left[] = $order === 'ASC' ? $a->$column : $b->$column; $right[] = $order === 'ASC' ? $b->$column : $a->$column; } return $left <=> $right; }); var_export($objects);

preferences:
91.06 ms | 406 KiB | 5 Q