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);
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array ( 4 => (object) array( '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' => '', ), 0 => (object) array( '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' => '', ), 3 => (object) array( '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' => '', ), 1 => (object) array( '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,….(10%); plants, antiques, firewood, cinema, theatre,…(13%)', 'spec_children_third_col' => '', ), 5 => (object) array( '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' => '', ), 2 => (object) array( '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' => '', ), )
Output for 7.2.0 - 7.2.33
array ( 4 => stdClass::__set_state(array( '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' => '', )), 0 => stdClass::__set_state(array( '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' => '', )), 3 => stdClass::__set_state(array( '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' => '', )), 1 => stdClass::__set_state(array( '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,….(10%); plants, antiques, firewood, cinema, theatre,…(13%)', 'spec_children_third_col' => '', )), 5 => stdClass::__set_state(array( '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' => '', )), 2 => stdClass::__set_state(array( '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' => '', )), )

preferences:
155.76 ms | 414 KiB | 5 Q