根据多数组中的键计算行跨度和列跨度数

发布于 2024-08-27 17:49:28 字数 1967 浏览 2 评论 0原文

我有这两种类型的布局,基本上,它可以是任何布局。我决定为此使用表格,因为使用 div 标签会导致某些可能的布局类型出现不良结果。

这里有两张图片描述了行和列的返回结果:

alt text http://acs. Graphicsmayhem.com/images/SimpleLayout.png

这将返回 $layout 数组,如下所示:

$layout[0][0]
$layout[0][1]
$layout[1][1]

在此布局类型中: $layout[1][0] 未设置,或未设置不存在。这里不存在第 1 行、第 0 列。那么我们如何使用它来帮助我们确定行跨度......?

替代文本 http://acs.graphicsmayhem.com/images/MoreComplexLayout.png

好的,此布局类型现在将返回以下内容:

$layout[0][0]
$layout[0][1]
$layout[1][0]
$layout[2][0]
$layout[2][1]
$layout[3][1]

再次,有一些未在此处设置:

$layout[1][1]
$layout[3][0]

好的,我有一个名为 $layout 的数组,它在行和列上执行 foreach,但它不会抓取行和列未设置的列。因此,我创建了一个 for 循环(具有正确的行数和列数)。这是我到目前为止得到的:

// $not_set = array();
for($x = 0; $x < $cols; $x++)
{
    $f = 0;
    for($p = 0; $p < $rows; $p++)
    {
        // $f = count($layout[$p]); 
        if(!isset($layout[$p][$x]))
        {
            $f++;
            // It could be a rowspan or a Colspan...
            // We need to figure out which 1 it is!

            /*
            $not_set[] = array(
                'row' => $p,
                'column' => $x,
            );
            */
        }

        // if ($rows - count($layout[$p]))

    }
}

好的,$layout 数组有 2 个键。第一个键是 [row],第二个键是 [column]。 现在循环遍历它们并确定它是否未设置,告诉我需要将 rowspan 或 colspan 放入某处。我完全迷失在这里了。

基本上,我希望在这里返回一个数组,如下所示:

$spans['row'][ row # ][ column # ] = Number of rowspans for that <td> element.
$spans['column'][ row # ][ column # ] = Number of colspans for that <td> element.

它要么需要 colspan,要么需要 rowspan,对于同一个 元素,它肯定永远不需要这两者。另外,上面的图片仅显示 2 列,可以有超过 2 列。

任何帮助将不胜感激!

I have these 2 types of layouts, basically, it can be any layout really. I have decided to use tables for this, since using div tags cause undesirable results in some possible layout types.

Here are 2 pics that describe the returned results of row and column:

alt text http://acs.graphicsmayhem.com/images/SimpleLayout.png

This would return the $layout array like so:

$layout[0][0]
$layout[0][1]
$layout[1][1]

In this layout type: $layout[1][0] is NOT SET, or doesn't exist. Row 1, Column 0 doesn't exist in here. So how can we use this to help us determine the rowspans...?

alt text http://acs.graphicsmayhem.com/images/MoreComplexLayout.png

Ok, this layout type would now return the following:

$layout[0][0]
$layout[0][1]
$layout[1][0]
$layout[2][0]
$layout[2][1]
$layout[3][1]

Again, there are some that are NOT SET in here:

$layout[1][1]
$layout[3][0]

Ok, I have an array called $layout that does a foreach on the row and column, but it doesn't grab the rows and columns that are NOT SET. So I created a for loop (with the correct counts of how many rows there are and how many columns there are). Here's what I got so far:

// $not_set = array();
for($x = 0; $x < $cols; $x++)
{
    $f = 0;
    for($p = 0; $p < $rows; $p++)
    {
        // $f = count($layout[$p]); 
        if(!isset($layout[$p][$x]))
        {
            $f++;
            // It could be a rowspan or a Colspan...
            // We need to figure out which 1 it is!

            /*
            $not_set[] = array(
                'row' => $p,
                'column' => $x,
            );
            */
        }

        // if ($rows - count($layout[$p]))

    }
}

Ok, the $layout array has 2 keys. The first 1 is [ row ] and the 2nd key is [ column ].
Now looping through them all and determining whether it's NOT SET, tells me that either a rowspan or a colspan needs to be put into something somewhere. I'm completely lost here.

Basically, I would like to have an array returned here, something like this:

$spans['row'][ row # ][ column # ] = Number of rowspans for that <td> element.
$spans['column'][ row # ][ column # ] = Number of colspans for that <td> element.

It's either going to need a colspan or a rowspan, it will definitely never need both for the same <td> element. Also, the pics above show for only 2 columns, there can be more than 2 columns.

Any help at all would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦欢 2024-09-03 17:49:28

为什么不存储 colspan &原始数组中的 rowspan 数据,而不是尝试导出它们?像这样的东西:

$layout[0][0][1][1]
$layout[0][1][1][1]
$layout[1][0][2][1]
$layout[2][0][1][2]
$layout[2][1][1][1]
$layout[3][1][1][1]

Why not store the colspan & rowspan datum in the original array, rather than trying to derive them? Something like this:

$layout[0][0][1][1]
$layout[0][1][1][1]
$layout[1][0][2][1]
$layout[2][0][1][2]
$layout[2][1][1][1]
$layout[3][1][1][1]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文