why this message come in php:notice undefined offset:2 <p>I want to use the project PHP Weather 2.2.2 but it has many problems here is a code </p> <pre><code>function get_languages($type) { static $output = array(); if (empty($output)) { /* I use dirname(__FILE__) here instead of PHPWEATHER_BASE_DIR * because one might use this function without having included * phpweather.php first. */ require(dirname(__FILE__) . '/languages.php'); $dir = opendir(dirname(__FILE__) . '/output'); while($file = readdir($dir)) { // I got a problem in this line below if (ereg("^pw_${type}_([a-z][a-z])(_[A-Z][A-Z])?\.php$", $file, $regs)) { // After i change it to the line mentioned below i got error undefined offset:2 in line 2 mentioned below // how to correct this error or is there any way to correct this code if(preg_match("#^pw_${type}_([a-z][a-z])(_[A-Z][A-Z])?\.php$#", $file, $regs)) { $output[$regs[1] . $regs[2]] = $languages[$regs[1] . $regs[2]]; } } closedir($dir); } asort($output); return $output; } </code></pre>