The sort weirdness is because $v gets reused as a by-value variable in the next foreach() loop down.

So you don't need to rewrite the loop to be more explicit, you just need to add an unset($v) after it.

```
foreach ($multicp_rows as &$v) { ksort($v); }
unset($v);
```