duanpu2272 2013-08-20 20:59
浏览 174
已采纳

foreach中的未定义变量[关闭]

I can not figure out why this is happening the following is my code. I am suspecting it has something to do with scope however I can var_dump $items just fine.

<?php
/*
* Setup the API scripts.
*/
require (dirname(__FILE__).'/vesu/SDK/Gw2/Gw2SDK.php');
require (dirname(__FILE__) .'/vesu/SDK/Gw2/Gw2Exception.php');

use \vesu\SDK\Gw2\Gw2SDK;
use \vesu\SDK\Gw2\Gw2Exception;
// Request a new instance of the API
$gw2 = new Gw2SDK(dirname(__FILE__).'/cache/items/', 604800);

// End of code header
function refreshCache($gw2){
    $i=0;
    $items = $gw2->getItems();
    #var_dump($items);
    foreach($items as $itemId){
        var_dump($itemsId);
        $item = $gw2->queryItemDetails($itemId);
        var_dump($item);
        $itemName = $item->name;
        echo "writing " . $itemId . "," . $itemName . "to the cache";
        $i++;
    }
    echo "Added " . $i . " Items to the cache.";
}
refreshCache($gw2);
?>
  • 写回答

2条回答 默认 最新

  • doucepei5298 2013-08-20 21:02
    关注

    You are calling var_dump($itemsId);.

    Your foreach loop is $itemId (no s at the end!)

    EDIT: sorry, didn't see it was answered!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料