Ask a master to give a Metro style layout
With table, the initial table has a total of 3 rows and 6 columns
Cell three sizes: 1x1 2x1 2x2, random
As shown in the following:
Thank you!
------to solve the idea----------------------
I'm going to give you a clue, adjust yourself.
$ar = Array (
Array (' 1x2 ', ' I'm the title '),
Array (' 2x2 ', ' I am the title '),
Array (' 1x2 ', ' I'm the title '),
Array (' 2x2 ', ' I am the title '),
Array (' 1x1 ', ' I'm the title '),
Array (' 1x1 ', ' I'm the title '),
Array (' 1x2 ', ' I'm the title '),
Array (' 1x2 ', ' I'm the title '),
Array (' 2x2 ', ' I am the title '),
Array (' 2x2 ', ' I am the title '),
Array (' 1x1 ', ' I'm the title '),
Array (' 1x1 ', ' I'm the title '),
Array (' 1x1 ', ' I'm the title '),
Array (' 1x1 ', ' I'm the title '),
);
Shuffle ($ar);
$box = Array (
Array (1, 1, 1, 1, 1, 1),
Array (1, 1, 1, 1, 1, 1),
Array (1, 1, 1, 1, 1, 1),
);
$res = Array ();
foreach ($ar as $ind = = $item) {
List ($h, $w) = Explode (' x ', $item [0]);
Find the placement from the top left corner
$flag = 0;
for ($y =0; $y
for ($x =0; $x
if ($box [$y] [$x] = = 1 && isset ($box [$y + $h -1][$x + $w-1]) && $box [$y + $h -1][$x + $w-1] = = 1) {
$flag + +;
Break 2;
}
}
}
if ($flag) {
$res [$y] = array (' c ' = = $w, ' r ' = = $h, ' V ' = $ind);
for ($i =0; $i < $h; $i + +) {
for ($j =0; $j < $w; $j + +) {
$box [$y + $i] [$x + $j] = 0;
}
}
}
}
echo "
"; foreach ($res as $row) {echo '
'; foreach ($row as $cell) {echo "
| {$ar [$cell [' V ']][1]} | "; } Echo '
';} echo "
";