I've never really had use for functions in the past, but now I do, so I'm trying to learn using a basic one I found on the web. Can someone explain why the word count is not being returned? I must be missing something very basic.

Thanks!

PHP Code:
function count_words($str) {$words 0;$str eregi_replace(" +"" "$str);$array explode(" "$str);for($i=0;$i count($array);$i++){if (eregi("[0-9A-Za-z---]"$array[$i])) $words++;}return $words;}

$str "hello there";
count_words($str);
echo 
$words