<?php
$in = [
["no" => "12345", "type" => 1],
["no" => "23456", "type" => 1],
["no" => "12345", "type" => 2],
];
$out = [];
foreach ($in as ["no" => $no, "type" => $type]) {
$out[$no][] = $type;
}
var_dump($out);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- array(2) {
[12345]=>
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
[23456]=>
array(1) {
[0]=>
int(1)
}
}
preferences:
67.33 ms | 402 KiB | 123 Q