|
Posted by Ewoud Dronkert on 09/18/05 04:02
news@celticbear.com wrote:
> $a = array();
> $a[0][0] = "Name";
> $a[0][1] = $name;
> $a[1][0] = "Message";
> $a[1][1] = $msg;
> $a[2][0] = "Subject";
> $a[2][2] = $subject;
I guess you mean [2][1] on the last line. A more instructive array
definition with the same result:
$a = array(
array('Name', $name),
array('Message', $msg),
array('Subject', $subj)
);
> foreach ($a as $v1) {
> $fieldname = $v1;
As you can see above, $a[0] is an array containing two items: 'Name' and
$name. So $v1 (an alias for $a[0], $a[1], etc.) is not the fieldname, but
$v1[0] is. A better way would be:
foreach ($a as $field) {
list($fieldname, $fieldvalue) = $field;
Or maybe even:
$a = array(
array('name' => 'Name', 'value' => $name),
array('name' => 'Message', 'value' => $msg),
array('name' => 'Subject', 'value' => $subj)
);
foreach ($a as $field)
echo "{$field['name']} = {$field['value']}<br />\n";
--
E. Dronkert
[Back to original message]
|