Reputation: 33
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'])){
.....
}
}
Upvotes: 0
Views: 246
Reputation: 1264
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'])
Upvotes: 3