Multiplay在foreach循环PHP中爆炸

问题描述 投票:-1回答:1

我有来自Yahoo的这个API,我想创建Breadcrumb使用它:

所以xml的结果是这样的:

<CategoryPath>Auction > Conputer > PC</CategoryPath>
<CategoryIdPath>0,23336,2084039759</CategoryIdPath>

我想要创建的是Breadcrumb

<ul class="breadcrumb">
    <li><a href="o">Auction</a></li>
    <li><a href="23336">Conputer</a></li>
    <li><a href="2084039759">PC</a></li>
</ul>

当然,每次它都是不同的值,所以我需要爆炸它们并将这两个爆炸放在一个foreach循环中。但我不知道怎么做......

有人可以告诉我我该怎么做或展示不同的方法?

php html laravel
1个回答
0
投票

首先得到数组:

$category_path = explode(' > ', $xml->Result->CategoryPath);
$category_path_id = explode(',', $xml->Result->CategoryIdPath);

然后结合它们:

$breadcrumbs = array_combine($category_path_id, $category_path);

然后循环它们(我使用Laravel Blade模板):

<ul class="breadcrumb">
    @foreach($breadcrumbs as $id => $name)
       <li><a href="?category={{ $id }}">{{ $name }}</a></li>
    @endforeach
</ul>
© www.soinside.com 2019 - 2024. All rights reserved.