我正在使用亚马逊产品API。
现在,
现在我使用上述代码时,我遇到了“第1行和第3行未定义索引:作者”的问题。
我尝试了以下方式:
$ItemAttr = $Item['ItemAttributes'];
现在,
$ItemAttr
包含一个多维数组。if(is_array($ItemAttr["Author"])){$Author = implode(", ", $ItemAttr["Author"]);
}else{
$Author = $ItemAttr["Author"];}
现在我使用上述代码时,我遇到了“第1行和第3行未定义索引:作者”的问题。
我尝试了以下方式:
if(isset($ItemAttr["Author"])) {
if(is_array($ItemAttr["Author"])){$Author = implode(", ", $ItemAttr["Author"]);
}else{
$Author = $ItemAttr["Author"];}
}
它消除了那个错误。
但是,当我使用这样的代码 $RetVal = array( 'Author' => $Author);
时,我会得到 Undefined variable : Author
错误。
有没有人能告诉我正确的方法呢?
请注意:$Item['ItemAttributes'];
可能包含Author
键,也可能不包含。我的意思是,如果返回的产品是一本书,该数组将返回作者键。否则它将不会。