我有这样的数组:
[mounts] => Array
(
[collected] => Array
(
[0] => Array
(
[name] => Chauffeured Mekgineer's Chopper
[itemId] => 120968
[qualityId] => 7
[icon] => inv_misc_key_06
)
[1] => Array
(
[name] => Albino Drake
[itemId] => 44178
[qualityId] => 4
[icon] => ability_mount_drake_blue
)
我需要每个数组的[name] [itemId] [qualityId] [icon](它们是数字[0] - [xy]
编辑代码:
$array = array('name'=>'xy','server'=>'frostwolf','fields'=>'mounts,stats');
$type = 'character';
$r = $client->fetch($type,$array);
echo '<pre>';
<?php foreach($r['result']['mounts']['collected'] as $item) { ?>
<div class="summary-inventory-simple">
<a href="//de.wowhead.com/item=<?php print $item['itemId']; ?>" class="<?php print $item['qualityId']; ?>">
<div class="iconmedium">
<img src="http://wow.zamimg.com/images/wow/icons/large/<?php print $item['icon']; ?>.jpg" alt="some_text" />
</a></div>
<?php } ?>
echo '</pre>';
我知道这应该可以用foreach,但不能让它工作。
答案 0 :(得分:0)
foreach($yourArr['mounts']['collected'] as $item) {
$item['name];
$item['other_key_what_you_need...']; ...
}
答案 1 :(得分:0)
你在......
<?php foreach($r['result']['mounts']['collected'] as $item) { ?>
<div class="summary-inventory-simple">
<a href="//de.wowhead.com/item=<?php print $item['itemId']; ?>" class="<?php print $item['qualityId']; ?>">
<div class="iconmedium">
<img src="http://wow.zamimg.com/images/wow/icons/large/<?php print $item['icon']; ?>.jpg" alt="some_text" />
</a></div>
<?php } ?>
PS。我不知道为什么你用$ r ['result']而不是$ r ['mounts'] ......