0

Below is an example of my array and in my code I'm trying to check if $champions (name of this whole array) isset$champions[$champion]['General'] and I get this error I need to check it since General array won't always exist

array (size=1)
  'Aatrox' => 
    array (size=1)
      'General' => 
        array (size=2)
          'Change' => 
            array (size=2)
              0 => string 'test.' (length=5)
              1 => string 'TEZd' (length=4)
          'Type' => 
            array (size=2)
              0 => string 'buff' (length=4)
              1 => string 'buff' (length=4)


foreach($champions as $champion){
        if(isset($champions[$champion]['General'])){
              ..... 
        }

}
2
  • Try: if(is_array($champions.... Commented Sep 22, 2015 at 12:22
  • @MaggsWeb tried that as well and tried empty same error every time Commented Sep 22, 2015 at 12:26

1 Answer 1

3
foreach($champions as $key => $champion){
    if(isset($champions[$key]['General'])){
          ..... 
    }

}

$champion would be the array containing the key 'General' if you want to access the array by index then you need to use the key instead.

Your other option would be isset($champion['General'])

Sign up to request clarification or add additional context in comments.

1 Comment

In the end I used foreach(array_keys($champions) as $champion){ but ill accept your answer in 3 mins as it is correct as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.