Added checks for valid array keys. CRM-12464

----------------------------------------
* CRM-12464:
  http://issues.civicrm.org/jira/browse/CRM-12464