doudonglu3764 2014-05-02 22:20
浏览 35
已采纳

php检查数组键是否设置且不等于

How can I do simple check in the following scenario. This is my array:

[data] => Array ( [0] => blog ... )

This does not seem to be working:

if(isset($data[1]) != "page") { 
   do stuff here...
}

I need to check if key [1] is set and value not equal to "page"

  • 写回答

4条回答 默认 最新

  • dongming5444 2014-05-02 22:42
    关注

    I found a better solution:

    if(!array_search("page", $data)) {
       // do stuff here
    }
    

    This works for me

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

报告相同问题?