Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/04/2022 in all areas

  1. My reply was a bit late so I did assume you were still working on it. Not everyone does, when they're waiting for replies, but you seemed more responsible than that. You're much closer. $chunks will be an array with a chunk for each column: $chunk[0] for the first, $chunk[1] for the second, and so on. That means each column doesn't need an additional foreach on $chunks itself. You only need the one foreach, and you run it on the appropriate $chunk[X] directly. No worries. I've been doing this long enough that I'm pretty good at spotting which people want help to work through the problem and which people want help so they don't have to do the work at all.
    1 point
  2. Then array_chunk won't be quite as helpful: it'll create 3 chunks of the same size and 1 of a remainder. I can't think of an easier way of doing this than creating your own chunks: <?php const COLUMNS = 4; $items = range(1, 98); $count = count($items); $base = floor($count / COLUMNS); // 24 $remainder = $count % COLUMNS; // 2 // so $base * COLUMNS + $remainder == $count $chunks = []; for ($start = 0; $start < $count; ) { // the base amount, plus one if there are any remainder to include $length = $base + ($remainder-- > 0 ? 1 : 0); $chunks[] = array_slice($items, $start, $length); $start += $length; } print_r($chunks); // [1-25, 26-50, 51-74, 75-98]
    1 point
  3. So if you open up your user settings, let's say the JSON file, you can see in there an entry for php.debug.executablePath with the correct file path? And another entry for php.validate.executablePath with the same file path?
    1 point
  4. Both of the messages there (the two that are actual errors, that is) tell you what to do. Have you done that?
    1 point
  5. What you currently do is chunk it into groups of 4 (so it goes 1,2,3,4; 5,6,7,8; 9,10,11,12) and then use array_column to get the Nth member of each group into the Nth column (column 1 has 1,5,9; column 2 has 2,6,10, etc). What you want to do is chunk it so there are 4 groups, and then put the contents of the Nth group into the Nth column. Now here's a question. If you have 10 items to put into those four columns, do you want 1 | 4 | 7 | 10 2 | 5 | 8 | 3 | 6 | 9 | where the last "column" is incomplete, or 1 | 4 | 7 | 9 2 | 5 | 8 | 10 3 | 6 | | where the last "row" is incomplete? The normal answer here, with the values going column-by-column, would be the first. That means there are ceil(10 items / 4 columns) = 3 items per column, except the last which has (10 items - 3 items per column * 3 columns not counting the last) = 1 item remaining. Fortunately you only need to figure out how many items you want in each of the 4 chunks - that is, ceil(number of items / number of columns). Then PHP will give you an array with four elements and each column can foreach over its respective chunk, just like you're doing now except you're asking it to chunk with the wrong number.
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.