簡體   English   中英

PHP未定義的索引..使用isset()與is_array()

[英]php undefined index..using isset() with is_array()

這是我的代碼:

if(is_array($ItemAttr["Actor"])){
  $Actors = implode(", ", $ItemAttr["Actor"]);
} else {
  $Actors = $ItemAttr["Actor"];
}

我得到了undefined index: Actor in **line 1** and **line 3**

我猜我應該使用isset()函數。 誰能告訴我如何將該函數與is_array()函數組合。

不知道這是否是您的意思,但是:

if( isset($ItemAttr["Actor"]) && is_array($ItemAttr["Actor"])){
    ....
}

在這種情況下,您要在訪問索引值之前檢查索引是否存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM