<?php
$arr = array (
0 =>
array (
'reference_no' => 'A0012',
'code' => 'HSWH30',
'net_unit_price' => '24000',
'quantity' => '2',
),
1 =>
array (
'reference_no' => 'A0012',
'code' => 'HSWH15',
'net_unit_price' => '21000',
'quantity' => '2',
),
2 =>
array (
'reference_no' => 'A0013',
'code' => 'HS-106AR',
'net_unit_price' => '2400',
'quantity' => '1',
),
3 =>
array (
'reference_no' => 'A0013',
'code' => 'HS-8012',
'net_unit_price' => '4500',
'quantity' => '2',
),
);
foreach($arr as $sub){
$new[$sub['reference_no']][] = $sub;
}
$new = array_values($new);
var_dump($new);
- Output for 5.6.38, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 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.26, 8.4.1 - 8.4.13
- array(2) {
[0]=>
array(2) {
[0]=>
array(4) {
["reference_no"]=>
string(5) "A0012"
["code"]=>
string(6) "HSWH30"
["net_unit_price"]=>
string(5) "24000"
["quantity"]=>
string(1) "2"
}
[1]=>
array(4) {
["reference_no"]=>
string(5) "A0012"
["code"]=>
string(6) "HSWH15"
["net_unit_price"]=>
string(5) "21000"
["quantity"]=>
string(1) "2"
}
}
[1]=>
array(2) {
[0]=>
array(4) {
["reference_no"]=>
string(5) "A0013"
["code"]=>
string(8) "HS-106AR"
["net_unit_price"]=>
string(4) "2400"
["quantity"]=>
string(1) "1"
}
[1]=>
array(4) {
["reference_no"]=>
string(5) "A0013"
["code"]=>
string(7) "HS-8012"
["net_unit_price"]=>
string(4) "4500"
["quantity"]=>
string(1) "2"
}
}
}
preferences:
144.26 ms | 410 KiB | 5 Q