I am trying to get the display logic to behave and stay where it is, and the code has turned into an interesting little problem that would be nice to do for a general solution.
Feel me, it looks like a wall with text, but I tried to format it using simple example data, so it should be clear after a quick walk.
If for some reason all this is a terrible idea, I need to inform before I create an insult to the gods.
Starting from such data, for example:
$data = array(
array(
'name' => 'Dave',
'age' => '21',
'city' => 'New York',
),
array(
'name' => 'Mike',
'age' => '19',
'city' => 'Chicago',
),
array(
'name' => 'John',
'age' => '21',
'city' => 'Chicago',
),
array(
'name' => 'Matt',
'age' => '19',
'city' => 'New York',
),
array(
'name' => 'Luke',
'age' => '21',
'city' => 'New York',
),
);
With an array of key names that can be used to group data, for example
$groups = array('city', 'age);
Then the data becomes:
$data = array(
'New York' => array(
'21' => array(
array(
'name' => 'Dave',
'age' => '21',
'city' => 'New York',
),
array(
'name' => 'Luke',
'age' => '21',
'city' => 'New York',
),
),
'19' => array(
array(
'name' => 'Matt',
'age' => '19',
'city' => 'New York',
),
),
),
'Chicago' => array(
'19' => array(
array(
'name' => 'Mike',
'age' => '19',
'city' => 'Chicago',
),
),
'21' => array(
array(
'name' => 'John',
'age' => '21',
'city' => 'Chicago',
),
),
),
);
" ", , -, , , , .
, , PHP. - ? , .