PHP Notice: Undefined index when looping array...
- by Jonathan
Hi, I'm looping a two-dimensional array like this:
if (!empty($aka)) {
foreach ($aka as $ak) {
if($ak["lang"]=="es") {
$sptitle=$ak["title"];
}
}
}
Pretty simple. If the array ($aka) is not empty I loop trough it and when it finds that the "lang" index is equal to "es" I just save the "title" value for that index in $sptitle.
The problem is that the array ($aka) contains a lot of information and sometimes there is no "lang" index... and I get this error: Notice: Undefined index: lang.
How can I fix this???
This is a extract of the array to help you understand. Notice that [1] doesn't have a [lang] index but [2] does have:
[1] => Array
(
[title] => The Lord of the Rings: The Motion Picture
[year] =>
[country] => USA
[comment] => promotional title
)
[2] => Array
(
[title] => Señor de los anillos: La comunidad del anillo, El
[year] =>
[country] => Argentina
[comment] => Chile, Mexico, Peru, Spain
[lang] => es
)
Thanks!