I have been trying to do this and i dont know why exactly its not working.. Here's the idea.
I want to receive the name and age of a person via POST method and then put it in an array dynamically, so that as more names and ages are added, the array is increased.
<?php
if (isset($_POST['submit'])){
$name= $_POST['name'];
$age= $_POST['age'];
foreach($array as $name=>$age){
$array[$name]= $age;
}
print_r($array);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action=" <?php $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="name"/>
age:<input type="text" name="age" />
<input type="submit" name="submit" value="Add to Array" />
</form>
</body>
</html>