Building a tool to manage text variables, found a php code in a blog that create an array from multiples form item. It works that way:
<?php
//Remove the spaces in PHP opening tag
$variable = $_POST['txtname'];
foreach( $variable as $n ) {
print "The name is ".$n ."</BR>";
}
?>
<html>
<body>
<form action="" method="post">
<p><label>Enter Name 1</label><input type="text" name="txtname[]" /><br /></p>
<p><label>Enter Name 2</label><input type="text" name="txtname[]" /><br /></p>
<p><label>Enter Name 3</label><input type="text" name="txtname[]" /><br /></p>
<input type="submit" value="Submit and display name by Array"/>
</form>
</body>
</html>
And it gives back a text like that:
The name is [FirstName]
The name is [SecondName]
The name is [ThirdName]
While I need multiple variables for each array, in this example let’s say add age at any people name to have such a result:
This entry is related to [FirstName] which is aged [Age1]
This entry is related to [SecondName] which is aged [Age2]
This entry is related to [ThirdName] which is aged [Age3]
I tried adding an “id” to the paragraph declaration and creating the array from that “id” attribute but it did not work, surely am missing some quite basic php rules but can’t find out which.
Thanks to show your support.