Forum Moderators: coopster
How do I create an array in my script and pass it as a variable in my Post array?
Hope this makes sense and Thanks!
$myArray=array(
'name'=>'John',
'job'=>'Director'
);
And then to produce the HTML you would do:
foreach ($myArray as $key => $value) {
print "<input type=\"text\" name=\"myArray[$key]\" value=\"$value\">\n";
}
which would print out
<input type="text" name="myArray[name]" value="John">
<input type="text" name="myArray[job]" value="Director">
For neater code I normally write this as
foreach ($myArray as $key => $value) {
printf('<input type="text" name="myArray[%s]" value="%s">',$key,$value);
}
Does that help?