<?php
$data = Array
(
0 => Array
(
'entry_id' => 1,
'ic' => 2147483647,
'name' => 'Kořínková Blanka',
'residency' => 'Štětí, Lukešova 354, 411 08',
'file_no' => 'KSUL 77 INS 18898 / 2013',
'detail' => '749371da-725c-4738-8def-2f7167142a6f'
),
1 => Array
(
'entry_id' => 1,
'ic' => 2147483647,
'name' => 'Kořínková Blanka',
'residency' => 'Štětí, Lukešova 354, 411 08',
'file_no' => 'KSUL 77 INS 21218 / 2013',
'detail' => '43b6a718-4647-451d-9c53-50dfee8403ff'
),
2 => Array
(
'entry_id' => 2,
'ic' => 46900217,
'name' => 'ENTEC a.s. "v likvidaci"',
'residency' => 'Staré Město, Brněnská 1916, 686 03',
'file_no' => 'KSBR 28 INS 1232 / 2013',
'detail' => 'e2155a52-c464-4357-b71b-4f4ff75585eb'
)
);
$mergeId = 'entry_id';
$data = array_reduce($data, function($c, $x) use ($mergeId)
{
$c[$x[$mergeId]] = isset($c[$x[$mergeId]])
?array_combine(
$z=array_keys($c[$x[$mergeId]]),
array_map(function($y) use ($x, $c, $mergeId)
{
return in_array($x[$y], (array)$c[$x[$mergeId]][$y])
?$c[$x[$mergeId]][$y]
:array_merge((array)$c[$x[$mergeId]][$y], [$x[$y]]);
}, $z)
)
:$x;
return $c;
}, []);
var_dump($data);
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array(2) {
[1]=>
array(6) {
["entry_id"]=>
int(1)
["ic"]=>
int(2147483647)
["name"]=>
string(19) "Kořínková Blanka"
["residency"]=>
string(31) "Štětí, Lukešova 354, 411 08"
["file_no"]=>
array(2) {
[0]=>
string(24) "KSUL 77 INS 18898 / 2013"
[1]=>
string(24) "KSUL 77 INS 21218 / 2013"
}
["detail"]=>
array(2) {
[0]=>
string(36) "749371da-725c-4738-8def-2f7167142a6f"
[1]=>
string(36) "43b6a718-4647-451d-9c53-50dfee8403ff"
}
}
[2]=>
array(6) {
["entry_id"]=>
int(2)
["ic"]=>
int(46900217)
["name"]=>
string(24) "ENTEC a.s. "v likvidaci""
["residency"]=>
string(38) "Staré Město, Brněnská 1916, 686 03"
["file_no"]=>
string(23) "KSBR 28 INS 1232 / 2013"
["detail"]=>
string(36) "e2155a52-c464-4357-b71b-4f4ff75585eb"
}
}
- Output for 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected '[' in /in/4uQCs on line 48
Process exited with code 255.
preferences:
287.48 ms | 401 KiB | 412 Q