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 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程