S
S
sadieff2018-11-25 12:47:06
PHP
sadieff, 2018-11-25 12:47:06

How to make a uniform selection from an array?

Good day!
Unable to create an algorithm. There is an array with a certain number of elements. It is necessary to distribute ALL elements of the array into groups, according to N elements, and so that the categories are distributed evenly.

$arr = Array(
  "Категория 1" => Array(
    "Товар 1",
    "Товар 2",
    "Товар 3",
    ...
    "Товар 30",
  ),
  "Категория 2" => Array(
    "Товар 1",
    "Товар 2",
    "Товар 3",
    ...
    "Товар 20",
  ),
  "Категория 3" => Array(
    "Товар 1",
    "Товар 2",
    "Товар 3",
    ...
    "Товар 10",
  ),
);

Those. if I wanted to make a selection from the $arr array, then it would return 10 times 6 elements each, where 3 products are from Category 1, 2 products are from Category 2 and 1 product is from Category 3. Can you tell me in which direction to move?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question