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);
?>

You are calling var_dump($itemsId);.

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

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

You just made a mistake when you copied over your debug code:

var_dump($items);

to the second place where you then turned it into:

var_dump($itemsId);
              ^- copied but forgotten to remove "s" from earlier

So next time you copy and paste code you need to take more care. Learn from your own mistakes into which problems you tend to walk.

And var_dump() stinks for debugging, use a step debugger and unit-tests instead.