问题的标题可能难以解释,以下是可能有帮助的代码
$containers = array(); // array of arrays
for ($index = 0; $index < 4; $index++) {
$containers[] = array(); // each element of the array is an array
}
foreach ($objects as $object) {
$index = computeIndex($object); // compute the index into the $containers
$container = $containers[$index]; // get the subarray object
$container[] = $object; // append $object to the end of the subarray
$containers[$index] = $container; // <--- question: is this needed?
}
所以正如问题所示,我还需要将子数组重新分配回数组吗?如果它是数组中元素的引用,那么我认为我不需要。