Hi I have an array like the following:
$originalArray = [
'Furniture/Fixture' => [
[
'LedgerId' => '557af7adc3acc3ac2b8b4567',
'groupName' => 'Furniture/Fixture',
'weightage' => 29,
'ledgerName' => 'Furniture & Fixture',
],
[
'LedgerId' => '558ffa02c3acc331258b4567',
'groupName' => 'Furniture/Fixture',
'weightage' => 28,
'ledgerName' => 'Water Coolers,Referigerator',
],
],
'Building' => [
[
'LedgerId' => '5586c5eec3acc3f42c8b4567',
'groupName' => 'Building',
'weightage' => 26,
'ledgerName' => 'Main Building',
],
[
'LedgerId' => '5586c85cc3acc38e2e8b4567',
'groupName' => 'Building',
'weightage' => 22,
'ledgerName' => 'Jr.School Building',
],
],
'Vehicle' => [
[
'LedgerId' => '55898004c3acc38b758b4567',
'groupName' => 'Vehicle',
'weightage' => 37,
'ledgerName' => 'School Bus',
],
[
'LedgerId' => '55898078c3acc3c5758b4567',
'groupName' => 'Vehicle',
'weightage' => 27,
'ledgerName' => 'Staff Car - TATA Mobile',
],
],
'Plant & Machinery' => [
[
'LedgerId' => '557af81fc3acc3ed2b8b4567',
'groupName' => 'Plant & Machinery',
'weightage' => 18,
'ledgerName' => 'Tools For Carpentres',
],
[
'LedgerId' => '557afff7c3acc38d2e8b4567',
'groupName' => 'Plant & Machinery',
'weightage' => 29,
'ledgerName' => 'Water Heating Equipment',
],
[
'LedgerId' => '557b004dc3acc3bf2e8b4567',
'groupName' => 'Plant & Machinery',
'weightage' => 28,
'ledgerName' => 'Mess Cold Room',
],
],
];
I want to sort each associative array, like Furniture/Fixture
and Buildings
, using the key inside each array weightage
.
How can I solve it, so that the output looks like this?
Array
([Building] => Array
(
[0] => Array
(
[LedgerId] => 5586c5eec3acc3f42c8b4567
[groupName] => Building
[weightage] => 26
[ledgerName] => Main Building
)
[1] => Array
(
[LedgerId] => 5586c85cc3acc38e2e8b4567
[groupName] => Building
[weightage] => 26
[ledgerName] => Jr.School Building
)
)
[Vehicle] => Array
(
[0] => Array
(
[LedgerId] => 55898004c3acc38b758b4567
[groupName] => Vehicle
[weightage] => 27
[ledgerName] => School Bus
)
[1] => Array
(
[LedgerId] => 55898078c3acc3c5758b4567
[groupName] => Vehicle
[weightage] => 27
[ledgerName] => Staff Car - TATA Mobile
)
)
[Plant & Machinery] => Array
(
[0] => Array
(
[LedgerId] => 557af81fc3acc3ed2b8b4567
[groupName] => Plant & Machinery
[weightage] => 28
[ledgerName] => Tools For Carpentres
)
[1] => Array
(
[LedgerId] => 557afff7c3acc38d2e8b4567
[groupName] => Plant & Machinery
[weightage] => 28
[ledgerName] => Water Heating Equipment
)
)
[Furniture/Fixture] => Array
(
[0] => Array
(
[LedgerId] => 557af7adc3acc3ac2b8b4567
[groupName] => Furniture/Fixture
[weightage] => 29
[ledgerName] => Furniture & Fixture
)
[1] => Array
(
[LedgerId] => 558ffa02c3acc331258b4567
[groupName] => Furniture/Fixture
[weightage] => 29
[ledgerName] => Water Coolers,Referigerator
)
)
)
Thanks in advance.