As a work-around to accessing a form field of type array within $_POST, I have found that assigning the from field of type array to a local var ($temp_ar), then accessing the desired cell by index as usual ($temp_ar[2])😉 works correctly.
However, still looking for the correct syntax to access a form field of type array within $POST directly. (e.g. $POST['testfld'][2]) //produces a syntax error)
<php>
<?php
define('HOST', $SERVER['HTTP_HOST']);
define('URI', rtrim(dirname($SERVER['PHP_SELF']), '/\'));
define('BASE_URL', "http://" . HOST . URI . "/test2.php");
$str .= "<form action='" . BASE_URL . "' method='post' name='f1'>";
$str .= "<input type='text' name='testfld[]' size=3 value='a'><br>";
$str .= "<input type='text' name='testfld[]' size=3 value='b'><br>";
$str .= "<input type='text' name='testfld[]' size=3 value='c'><br>";
$str .= "<br><input type='submit' name='btn' value='Go'>";
$str .= "</form>";
echo $str;
echo("<br>POST ");
var_dump($_POST);
if (is_array($_POST['testfld']))
echo("<br>testfld is array");
else
echo("<br>testfld not array");
echo("<br>testfld ar ");
foreach($_POST['testfld'] as $key => $val) {
echo("<br>" . $key . " - " . $val);
}
$temp_ar = $_POST['testfld'];
echo("<br>testfld2: " . $temp_ar[2]);
//echo("<br>testfld2: " . $_POST['testfld'][2]); //syntax error
?>
</php>
OUTPUT:
POST array(2) { ["testfld"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } ["btn"]=> string(2) "Go" }
testfld is array
testfld ar
0 - a
1 - b
2 - c
testfld2: c