Ask PHP algorithm, two-dimensional array to take out one-dimensional array of the same ID as several new two-dimensional arrays.
Little brother just learned PHP soon, encountered a problem, ask the heroes, thank you!
The two-dimensional array is as follows;
$arr = Array (
Array (' ID ' =>100, ' value ' =>100),
Array (' ID ' =>100, ' value ' =>130,
Array (' ID ' =>100, ' value ' =>140),
Array (' ID ' =>100, ' value ' =>150),
Array (' ID ' =>101, ' value ' =>1600),
Array (' ID ' =>101, ' value ' =>100),
Array (' ID ' =>102, ' value ' =>100),
Array (' ID ' =>102, ' value ' =>100),
Array (' ID ' =>102, ' value ' =>100),
Array (' ID ' =>103, ' value ' =>100),
Array (' ID ' =>103, ' value ' =>100),
Array (' ID ' =>104, ' value ' =>100),
Array (' ID ' =>104, ' value ' =>100),
Array (' ID ' =>104, ' value ' =>100),
Array (' ID ' =>105, ' value ' =>100)
);
How to split into the following 5 two-dimensional arrays:
ARR1 (
Array (' ID ' =>100, ' value ' =>100),
Array (' ID ' =>100, ' value ' =>130,
Array (' ID ' =>100, ' value ' =>140),
Array (' ID ' =>100, ' value ' =>150)
);
ARR2 (
Array (' ID ' =>101, ' value ' =>1600),
Array (' ID ' =>101, ' value ' =>100)
);
ARR3 (
Array (' ID ' =>102, ' value ' =>100),
Array (' ID ' =>102, ' value ' =>100),
Array (' ID ' =>102, ' value ' =>100)
);
ARR4 (
Array (' ID ' =>103, ' value ' =>100),
Array (' ID ' =>103, ' value ' =>100)
);
ARR5 (
Array (' ID ' =>104, ' value ' =>100),
Array (' ID ' =>104, ' value ' =>100),
Array (' ID ' =>104, ' value ' =>100),
Array (' ID ' =>105, ' value ' =>100)
);
ARR5 (
Array (' ID ' =>105, ' value ' =>100)
); PHP two-dimensional arrays algorithm
Share to:
------Solution--------------------
$arr = Array (
Array (' ID ' =>100, ' value ' =>100),
Array (' ID ' =>100, ' value ' =>130),
Array (' ID ' =>100, ' value ' =>140),
Array (' ID ' =>100, ' value ' =>150),
Array (' ID ' =>101, ' value ' =>1600),
Array (' ID ' =>101, ' value ' =>100),
Array (' ID ' =>102, ' value ' =>100),
Array (' ID ' =>102, ' value ' =>100),
Array (' ID ' =>102, ' value ' =>100),
Array (' ID ' =>103, ' value ' =>100),
Array (' ID ' =>103, ' value ' =>100),