在Laravel视图的表中显示[来自PHP列表]的多列数据

在Laravel视图的表中显示[来自PHP列表]的多列数据,php,html,laravel,Php,Html,Laravel,我目前正在使用带有以下HTML的Laravel视图,该视图使用标记将数据显示到表中 @if($unrostered) <table class="table table-hover table-striped"> <thead> <tr> <th>#</th> <th>Name</th> </tr>

我目前正在使用带有以下HTML的Laravel视图,该视图使用
标记将数据显示到表中

@if($unrostered)
    <table class="table table-hover table-striped">
        <thead>
        <tr>
            <th>#</th>
            <th>Name</th>
        </tr>
        </thead>
        <tbody>
            <?php $index = 1; ?>
            @foreach($unrostered as $name => $profile)
                <tr>
                    <td>
                        <?= $index; $index++; ?>
                    </td>
                    <td>
                        <a
                            href="{{ $profile }}">{{ $name }}
                        </a>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
@endif
@if($unrostered)
#
名称
@foreach($name=>$profile)
@endforeach
@恩迪夫
我目前正在使用一个名为
$unrostered
的关联列表,其中包含名为
name
profile
的键和值。这显示了两列数据,如下所示:

如您所见,
name
变量是此人的姓名,
profile
是链接到其个人资料的URL

我的HTML技能不好。我想将多个[长度相同]的列表传递到我的HTML表中,这样每个列表就占据了它们自己的列


我试着处理行和数据标记,但是,我所能做到的只是所有数据点只占用一行而不是一列。

假设其他列表的名称是
$list1,$list2,…
,它们的格式与
$unrostered
相同。然后,您的
foreach
代码应更改为:

        <?php $index = 1; ?>
        @foreach($unrostered as $name => $profile)
            <tr>
                <td>
                    <?= $index; $index++; ?>
                </td>
                <td>
                    <a
                        href="{{ $profile }}">{{ $name }}
                    </a>
                </td>
                <td>
                    <a
                        href="{{ $list1[$name] }}">{{ $name }}
                    </a>
                </td>
                <td>
                    <a
                        href="{{ $list2[$name] }}">{{ $name }}
                    </a>
                </td>
            </tr>
        @endforeach

@foreach($name=>$profile)
@endforeach

您当前有多少个列表?每个列表的数据格式是什么?我目前有一个名为$unrostered的关联列表,它显示在Blade模板中。数据格式可以是字符串或整数,但您在问题中提到“我想传入多个列表”。您的多个列表是什么?@tuananh我还没有这些列表,因为我不知道如何将每个列表显示为列,但它们的大小将与$unrostered相同。它们将包含URL,它们的格式是否与
$unrostered
相同?像
$name=>$url
?如果我没有错的话,您使用
$list1[$name]
来获取url和
$name
来获取用户名?您提到所有列表的格式都是
$name=>$url
,因此
$list1[$name]
应该会给你相应的
$url
$unrostered[$name]
是的,我认为这很有效!如果我有任何问题,我会让你进一步知道!