Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Check if array key exists

I'm getting Notice: Undefined offset: 0 for the code below
preg_match_all("/\[Image(?:_?)(\d+)\]/i", $DiscussionImage, $matches); if ($matches[1][0]) {}

For some cases the preg will fail and when it does, $matches[1][0] doesn't exist only $matches[1] does, hence the notice.
Checking if its an array doesn't work cause even if it fails its type is array.

So $matches[1] exists whether preg fails or passes
$matches[1][0] exists if preg passes.

Any idea. how to check for it.


  • Options
    Nevermind solved it
    $MatchCount = preg_match_all("/\[Image(?:_?)(\d+)\]/i", $DiscussionImage, $matches); if ($MatchCount) {}
This discussion has been closed.