I am having a bit of a brain freeze today. I am writing a function, and as part of the function, I want a counter to be incriminated, and a record added to my function. This should run after a form is submitted, so it checks how many name/email combos have been submitted, and ads them to the array accordingly.

The code I have, looks like this

Code PHP:
$i=0;
$people = array();
if(isset($_POST['submitMe'])){
	function writeArray($name,$email){
		$i++;
		echo $i;
		$people[$name] = $email;
		print_r($people);
	}
 
	if($_POST['name1']!=NULL){
		writeArray($_POST['name1'],$_POST['email1']);
	}
	if($_POST['name2']!=NULL){
		writeArray($_POST['name2'],$_POST['email2']);
	}
}

So if in the form, I enter a name into both name 1 and 2 fields, I'll get output like this:

Code:
1Array ( [Dan Smith] => dan.smith@example.com )
1Array ( [Joe Blow] => joe@blow.com )
It seems to not save the previous name, and just creates a new array with 1 user. The counter is also not incremented. How can I get my counter to show 2, and both of these gentlemen's names to be shown?