`$category['attributes']` coul be `null` not every category must have attributes. do `if (isset($category['attributes'])) {}` around the `foreach` block