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); $column = 'spec_children_name'; $direction = 'asc'; $reverser = $direction === 'asc' ? 1 : -1; uasort($objects, function($a, $b) use ($column, $reverser) { return $reverser * ($a->$column <=> $b->$column); }); 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 ( 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' => '', ), 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' => '', ), 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' => '', ), 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' => '', ), 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' => '', ), )
Output for 7.2.0 - 7.2.33
array ( 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' => '', )), 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' => '', )), 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' => '', )), 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' => '', )), 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' => '', )), )

preferences:
133.52 ms | 418 KiB | 6 Q