PHP PHP Function idx() for accessing array values safely

Learn how to use the PHP function idx() to safely access array values without getting undefined index notices. This function returns NULL if the value doesn't exist in the array.

<?php
function idx( $array, $key ) {
  if ( isset( $array[$key] ) ) {
    return $array[$key];
  } else {
    return NULL;
  }
}